Multiple lattice plots with gridExtra

删除回忆录丶 提交于 2019-12-18 12:43:03

问题


There is very convenient way of plotting multiple graphs and that's with gridExtra - grid.arrange:

grid.arrange(plot1,plot2,plot3,plot4,plot5,plot6,plot7,plot8,plot9, ncol=3)

The above command draws 3x3 graphs in one window.

Now, I'm using my own lattice setup to draw unique lines etc. via

trellis.par.set(my.setup)

However using the grid.arrange command for plotting multiple plots won't pass on the setup as the output plots are in default colours.

So the question is how to pass on the my.setup onto grid.arrange or alternatively how to plot easily multiple graphs in one go for lattice.

EDIT: Reproducible example:

Data <- data.frame(Col1=rnorm(10,0,1),Col2=rexp(10,2),Col3=rnorm(10,2,2),Col4=runif(10,0,2), 
       Time=seq(1,10,1))

trellis.par.set(col.whitebg()) 
newSet <- col.whitebg() 
newSet$superpose.symbol$col <- c("blue3","orange2","gray1","tomato3")
newSet$superpose.symbol$pch <- 1
newSet$superpose.symbol$cex <- 1
newSet$superpose.line$col <- c("blue3","orange2","gray1","tomato3")
trellis.par.set(newSet)

Plot1 <- xyplot(Col1+Col2~Time, Data, type="spline")
Plot2 <- xyplot(Col2+Col3~Time, Data, type="spline")
Plot3 <- xyplot(Col1+Col3~Time, Data, type="spline")
Plot4 <- xyplot(Col3+Col4~Time, Data, type="spline")

grid.arrange(Plot1,Plot2,Plot3,Plot4, ncol=2)

回答1:


I guess it's got something to do with the plot.trellis method not finding the global theme settings when it's wrapped in gridExtra::drawDetails.lattice. I don't understand these lattice options, but as far as I recall you can specify them explicitly at the plot level too,

pl = list(Plot1, Plot2, Plot3, Plot4)
# do.call(grid.arrange, c(pl, nrow=1))
do.call(grid.arrange, c(lapply(pl, update, par.settings=newSet), list(nrow=1)))



来源:https://stackoverflow.com/questions/18419756/multiple-lattice-plots-with-gridextra

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!