def makeImage(rates): out = tempfile.NamedTemporaryFile(suffix='.png') grdevices = importr('grDevices') grdevices.png(file=out.name, width=512, height=512) try: grid.newpage() lt = grid.layout(1, 1) vp = grid.viewport(layout=lt) vp.push() vp = grid.viewport(**{'layout.pos.col': 1, 'layout.pos.row': 1}) for row, (year, count) in enumerate(sorted(rates['byYear'].items())): grid.rect(x=grid.unit(.5, "npc"), y=grid.unit(row / len(rates['byYear']), "npc"), width=grid.unit(count / 15000, "npc"), height=grid.unit(.95 / len(rates['byYear']), "npc"), vp=vp).draw() finally: grdevices.dev_off() return open(out.name).read()
def makeImage(rates): out = tempfile.NamedTemporaryFile(suffix='.png') grdevices = importr('grDevices') grdevices.png(file=out.name, width=512, height=512) try: grid.newpage() lt = grid.layout(1, 1) vp = grid.viewport(layout = lt) vp.push() vp = grid.viewport(**{'layout.pos.col':1, 'layout.pos.row': 1}) for row, (year, count) in enumerate(sorted(rates['byYear'].items())): grid.rect(x=grid.unit(.5, "npc"), y=grid.unit(row / len(rates['byYear']), "npc"), width=grid.unit(count / 15000, "npc"), height=grid.unit(.95 / len(rates['byYear']), "npc"), vp = vp).draw() finally: grdevices.dev_off() return open(out.name).read()
pp = gp + \ ggplot2.aes_string(x='wt', y='mpg') + \ ggplot2.geom_point() pp.plot() #-- ggplot2mtcars-end grdevices.dev_off() grdevices.png('../../_static/graphics_ggplot2geombin2d.png', width=1000, height=350, antialias="subpixel", type="cairo") grid.newpage() grid.viewport(layout=grid.layout(1, 3)).push() vp = grid.viewport(**{'layout.pos.col': 1, 'layout.pos.row': 1}) #-- ggplot2geombin2d-begin gp = ggplot2.ggplot(dataf_rnorm) pp = gp + \ ggplot2.aes_string(x='value', y='other_value') + \ ggplot2.geom_bin2d() + \ ggplot2.ggtitle('geom_bin2d') pp.plot(vp=vp) #-- ggplot2geombin2d-end vp = grid.viewport(**{'layout.pos.col': 2, 'layout.pos.row': 1}) #-- ggplot2geomdensity2d-begin gp = ggplot2.ggplot(dataf_rnorm)
width = 612, height = 612, antialias="subpixel", type="cairo") #-- ggplot2mtcars-begin gp = ggplot2.ggplot(mtcars) pp = gp + \ ggplot2.aes_string(x='wt', y='mpg') + \ ggplot2.geom_point() pp.plot() #-- ggplot2mtcars-end grdevices.dev_off() grdevices.png('../../_static/graphics_ggplot2geombin2d.png', width = 1000, height = 350, antialias="subpixel", type="cairo") grid.newpage() grid.viewport(layout=grid.layout(1, 3)).push() vp = grid.viewport(**{'layout.pos.col':1, 'layout.pos.row': 1}) #-- ggplot2geombin2d-begin gp = ggplot2.ggplot(dataf_rnorm) pp = gp + \ ggplot2.aes_string(x='value', y='other_value') + \ ggplot2.geom_bin2d() + \ ggplot2.opts(title = 'geom_bin2d') pp.plot(vp = vp) #-- ggplot2geombin2d-end vp = grid.viewport(**{'layout.pos.col':2, 'layout.pos.row': 1}) #-- ggplot2geomdensity2d-begin gp = ggplot2.ggplot(dataf_rnorm)
def r_grid(nrows, ncols): lt = grid.layout(nrows, ncols) vp = grid.viewport(layout = lt) vp.push() return vp