首页 文章

使用gridExtra的多个点阵图

提问于
浏览
2

有一种非常方便的方法来绘制多个图形,并且使用gridExtra - grid.arrange

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

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

现在,我正在使用我自己的点阵设置来绘制独特的线条等

trellis.par.set(my.setup)

但是,使用grid.arrange命令绘制多个绘图将不会传递设置,因为输出绘图是默认颜色 .

所以问题是如何将 my.setup 传递给grid.arrange,或者如何在格子中一次性容易地绘制多个图形 .

编辑:可重复的例子:

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 回答

  • 7

    我想这与 plot.trellis 方法在 gridExtra::drawDetails.lattice 包装时没有找到全局主题设置有关 . 我不明白这些格子选项,但据我记得你也可以在情节层面明确指定它们,

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

    enter image description here

相关问题