Re: [R] storing ggplot objects as components of a vector

From: ONKELINX, Thierry <>
Date: Fri, 15 Feb 2008 10:38:35 +0100

You'll need to store it in a list rather than a vector.

DF<-data.frame(A=rnorm(12),B=c(1:12),C=rep(c(1:4),each=3)) Q <- list()
PAC<-geom_point(mapping=aes(x=A,y=B),data=DF[DF$C==1,]) P<-ggplot()+PAC
Q[[length(Q) + 1]] <- P

You could shorten this into

DF<-data.frame(A=rnorm(12),B=c(1:12),C=rep(c(1:4),each=3)) Q <- list()
Q[[length(Q) + 1]] <- ggplot(DF[DF$C==1,], aes(x=A,y=B)) + geom_point() Q[[1]]

HTH, Thierry

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4
9500 Geraardsbergen
tel. + 32 54/436 185

Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney

-----Oorspronkelijk bericht-----
Van: [] Namens Gallego Liberman, Matias Verzonden: vrijdag 15 februari 2008 10:09 Aan:
Onderwerp: [R] storing ggplot objects as components of a vector


I have a lot of plots that i need to store as components of a vector. Here you have an example

> DF<-data.frame(A=rnorm(12),B=c(1:12),C=rep(c(1:4),each=3))
> Q<-c()
> length(Q)<-3
> PAC<-geom_point(mapping=aes(x=A,y=B),data=DF[DF$C==1,])
> P<-ggplot()+PAC
> P #generates the plot
> Q[1]<-P
Warning message:
In Q[1] <- P :
  número de items para para sustituir no es un múltiplo de la longitud del reemplazo
> Q[1]

NULL I guess the problem is the class of Q[1]. if so, what class should I coerce Q to for the sentence: > Q[1] to generate the plot as > P does?

thanks in advance

        [[alternative HTML version deleted]] mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri 15 Feb 2008 - 09:57:13 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 Fri 15 Feb 2008 - 10:30:14 GMT.

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

list of date sections of archive