예제 #1
0
def render_plot(gp, args):
  """Render a plot using ggplot

  :gp: A base ggplot2 object
  :x: The x value expression
  :y: The y value expression
  :type: The type of plot to make

  """
  args = util.Namespace(args)

  import rpy2.robjects.lib.ggplot2 as ggplot2

  pp = gp + ggplot2.aes_string(x=args.x,
                               y=args.y)

  if args.type == 'points':
    pp += ggplot2.geom_point()
  elif args.type == 'lines':
    pp += ggplot2.geom_line()
  elif args.type == 'boxplot':
    pp += ggplot2.geom_boxplot()
  else:
    raise Exception("{0} not implemented".format(args.type))

  if args.facets is not None:
    try:
      pp += ggplot2.facet_grid(ro.Formula(args.facets))
    except Exception:
      pass

  try:
    pp.plot()
  except Exception:
    pass
예제 #2
0
     ggplot2.geom_point()

pp.plot()
#-- ggplot2mtcarscolcyl-end
grdevices.dev_off()

grdevices.png('../../_static/graphics_ggplot2_ggplot_1.png',
              width=936,
              height=312,
              antialias="subpixel",
              type="cairo")
#-- ggplot1-begin
pp = gp + \
     ggplot2.aes_string(x='wt', y='mpg') + \
     ggplot2.geom_point() + \
     ggplot2.facet_grid(ro.Formula('. ~ cyl'))

pp.plot()
#-- ggplot1-end
grdevices.dev_off()

grdevices.png('../../_static/graphics_ggplot2aescolsize.png',
              width=612,
              height=612,
              antialias="subpixel",
              type="cairo")
#-- ggplot2aescolsize-begin
pp = gp + \
     ggplot2.aes_string(x='wt', y='mpg', size='factor(carb)',
                 col='factor(cyl)', shape='factor(gear)') + \
     ggplot2.geom_point()
예제 #3
0
pp = (gp + ggplot2.aes_string(x='wt', y='mpg', col='factor(cyl)') +
      ggplot2.geom_point())

pp.plot()
#-- ggplot2mtcarscolcyl-end
grdevices.dev_off()

grdevices.png('../../_static/graphics_ggplot2_ggplot_1.png',
              width=936,
              height=312,
              antialias=ANTIALIAS,
              type="cairo")
#-- ggplot1-begin
pp = (gp + ggplot2.aes_string(x='wt', y='mpg') + ggplot2.geom_point() +
      ggplot2.facet_grid(ro.Formula('. ~ cyl')))

pp.plot()
#-- ggplot1-end
grdevices.dev_off()

grdevices.png('../../_static/graphics_ggplot2aescolsize.png',
              width=612,
              height=612,
              antialias=ANTIALIAS,
              type="cairo")
#-- ggplot2aescolsize-begin
pp = (gp + ggplot2.aes_string(x='wt',
                              y='mpg',
                              size='factor(carb)',
                              col='factor(cyl)',
예제 #4
0
pp = gp + \
     ggplot2.aes_string(x='wt', y='mpg', col='factor(cyl)') + \
     ggplot2.geom_point()

pp.plot()
#-- ggplot2mtcarscolcyl-end
grdevices.dev_off()


grdevices.png('../../_static/graphics_ggplot2_ggplot_1.png',
              width = 612, height = 612, antialias="subpixel", type="cairo")
#-- ggplot1-begin
pp = gp + \
     ggplot2.aes_string(x='wt', y='mpg') + \
     ggplot2.geom_point() + \
     ggplot2.facet_grid(ro.Formula('. ~ cyl'))


pp.plot()
#-- ggplot1-end
grdevices.dev_off()



grdevices.png('../../_static/graphics_ggplot2aescolsize.png',
              width = 612, height = 612, antialias="subpixel", type="cairo")
#-- ggplot2aescolsize-begin
pp = gp + \
     ggplot2.aes_string(x='wt', y='mpg', size='factor(carb)',
                 col='factor(cyl)', shape='factor(gear)') + \
     ggplot2.geom_point()