开发者

ggplot2: aspect_ratio and placing title/axis label in the right place

Using ggplot2 under R (and the code below uses rpy2, I don't actually know straight R, sorry).

I'm trying to add an aspect_ratio to my plot (so it'll fit nicely on a slide). The below example is pretty minimal. Aspect_ratio does the right thing EXCEPT the title and x-axis label are placed way above and below the plot, respectively, with a g开发者_如何学Goiant white space between the title and plot and between the plot and x-axis label, as in (plot here):

   TITLE TITLE


PLOT PLOT PLOT PLOT
PLOT PLOT PLOT PLOT
PLOT PLOT PLOT PLOT
PLOT PLOT PLOT PLOT


    x-axis label

Not cool. What can I do to squeeze them together?

#!/usr/bin/env python2.6
import rpy2.robjects.lib.ggplot2 as ggplot2
import rpy2.robjects as ro
from rpy2.robjects.packages import importr

df = ro.DataFrame({'x': ro.IntVector((1,2)), 'y': ro.IntVector((3,4))})
pp = ggplot2.ggplot(df) + \
    ggplot2.aes_string(x='x', y='y') + \
    ggplot2.opts(**{'title' : 'Title',
                    'aspect.ratio' : 0.618033989} ) + \
    ggplot2.geom_line()
grdevices = importr('grDevices')
grdevices.pdf(file="aspect.pdf")
pp.plot()
grdevices.dev_off()


This is a limitation in the current layout system, and something I hope to work on soon.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜