[R] overdrawing a plot

Dieter Menne dieter.menne at menne-biomed.de
Wed Feb 20 14:16:10 CET 2008


Gallego Liberman, Matias <m.gallego <at> isofoton.com> writes:

> When using grid.edit inside a pdf device it applies the changes on a
> second plot, not erasing the first one.
.. 
> >DF<-data.frame(A=c(1:12),B=c(1:12)*c(rnorm(12,mean=1)),C=2*c(1:12),D=re
> p(c(1:4),each=3))
> >trellis.device(pdf,file='prueba.pdf')
> >ggplot()+geom_line(mapping=aes(x=A,y=B,colour=D),data=DF)
> >grid.edit(gPath('legend'),gp=gpar(fontsize=8),grep=TRUE,redraw=TRUE)
> >dev.off()
> 
> produces a two pages pdf document, one with and one without the changes
> inttroduced by grid.edit
...

I had a similar problem, and Paul Murrell sent me a workaround:

http://finzi.psych.upenn.edu/R/Rhelp02a/archive/104038.html

"You can capture the ggplot drawing as a grid grob (gTree), edit that (no
drawing occurs to this point), and then draw it ..."

Hadley realized that this is a bit awkward, and it could be there is a better
solution in the post-christmas revision.

Dieter



More information about the R-help mailing list