[R] Print grid/ggplot to a metafile
p.murrell at auckland.ac.nz
Wed Jul 4 02:32:26 CEST 2007
Dieter Menne wrote:
> Dear UseRs called Hadley, or Paul,
> I am trying to print an edited ggplot2/grid graphics to a metafile. With the
> commented line below it works, but when I edit the plot by uncommenting the
> line, it fails, because it's illegal to have 2 graphics in a metafile. It
> works with pdf, but even then I get two plots, which is a nuisance.
> I found a workaround by using windows(); savePlot, but it only works in
> interactive mode, not when called with something like (Windows)
> rterm --no-save < printit.r
> Any ideas?
You can capture the ggplot drawing as a grid grob (gTree), edit that (no
drawing occurs to this point), and then draw it ...
gridggplot <- grid.grabExpr(print(ggplot(mtcars, aes(x=cyls)) +
modgridggplot <- editGrob(gridggplot,
> mtcars$cyls = factor(mtcars$cyl,
> ggplot(mtcars, aes(x=cyls)) + geom_bar()
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
64 9 3737599 x85392
paul at stat.auckland.ac.nz
More information about the R-help