使用gridExtra的多个格子图 [英] Multiple lattice plots with gridExtra

查看:84
本文介绍了使用gridExtra的多个格子图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种非常方便的绘制多个图形的方法,而这是使用gridExtra-grid.arrange:

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)

以上命令在一个窗口中绘制3x3图形.

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)

但是,由于输出图是默认颜色,因此使用grid.arrange命令绘制多个图不会在设置上通过.

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

所以问题是如何将my.setup传递到grid.arrange上,或者如何轻松地一次绘制多个图形以获得晶格.

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.

可复制的示例:

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)

推荐答案

我想这与plot.trellis方法有关,因为它包装在gridExtra::drawDetails.lattice中时找不到全局主题设置.我不理解这些晶格选项,但据我所知,您也可以在绘图级别显式指定它们,

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)))

这篇关于使用gridExtra的多个格子图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆