views:

17

answers:

1

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 giant white space between the title and plot and between the plot and x-axis label, as in (plot at http://tinyurl.com/2uo5y47):

   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()
A: 

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

hadley