If I put a "windows()" in front of the qplot command in the above code
and simply wanted to have each plot graphed on different pages...
Six graph windows opened but none of them had any content... they are
all blank...
What's the problem?
Thx
On 12/7/11, Michael <comtech.usa at gmail.com>
wrote:> Hi all,
>
> I am stuck at ploting multiple graphs on one page. I don't why it
doesn't
> work.
>
> All the 6 plots are either exactly the same, or they simply don't plot
> at all. I made sure that in each iteration the "datasub" and
> "factorsub" are different ...
>
> Could you please help me?
>
> Thanks a lot!
>
> I did my homework and followed the following advice:
>
>
http://stackoverflow.com/questions/1249548/side-by-side-plots-with-ggplot2-in-r
>
> my.multiplot <- function(..., plotlist=NULL, cols) {
> require(grid)
>
> # Make a list from the ... arguments and plotlist
> plots <- c(list(...), plotlist)
>
> numPlots = length(plots)
>
> # Make the panel
> plotCols = cols # Number of columns of plots
> plotRows = ceiling(numPlots/plotCols) # Number of rows needed,
> calculated from # of cols
>
> # Set up the page
> grid.newpage()
> pushViewport(viewport(layout = grid.layout(plotRows, plotCols)))
> vplayout <- function(x, y)
> viewport(layout.pos.row = x, layout.pos.col = y)
>
> # Make each plot, in the correct location
> for (i in 1:numPlots) {
> curRow = ceiling(i/plotCols)
> curCol = (i-1) %% plotCols + 1
> print(plots[[i]], vp = vplayout(curRow, curCol ))
> }
>
> }
>
>
> My code is as below:
>
> ----------------------------
>
>
> myplotlist=vector('list', 6)
> nCount=0;
>
> for (j in myyears)
> {
> print(j)
> nCount=nCount+1
>
> #...
> # prepare datasub and factorsub for different j...
> #...
> tmp<-data.frame(as.double(datasub),as.numeric(factorsub))
> tt=qplot(factor(as.numeric(factorsub)),as.double(datasub),data=tmp,geom
> = "boxplot",ylab='Chg',xlab='Hours', main=j)
>
> myplotlist[nCount]=tt
>
> }
>
> my.multiplot(plotlist=myplotlist,cols=3)
>