Re: [R] overdrawing a plot

From: Dieter Menne <>
Date: Wed, 20 Feb 2008 13:16:10 +0000 (UTC)

Gallego Liberman, Matias <m.gallego <at>> 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)
> >
> 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:

"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 mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed 20 Feb 2008 - 13:20:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 23 Feb 2008 - 18:30:16 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive