Adding multiple plots at one page grid.arrange function

I am plotting 15 scatter plots which include regression lines. However, I would like to display on one page to visualize better. grid.arrange function helps to add multiple plots according to our interest however, I always face with an error.

Error in gList(list(wrapvp = list(x = 0.5, y = 0.5, width = 1, height = 1, : only 'grobs' allowed in "gList"

plots <- list() 
for (i in 1:(ncol(xx2)-1)) {

  cn <- colnames(xx2)

  reg<-lm(xx2[,i]~xx2[,16], data=data.frame(xx2))
  aa<-summary(reg)
  p1<-plot(xx2[,16], xx2[,i],  xlab=cn[16], ylab=cn[i], 
       pch=1, cex.main=1.5, frame.plot=FALSE, col="grey")+ abline(reg, col="blue", lwd=2) + text(max(xx2[,16]/1.3), max(xx2[,i])/2, paste("R-Squared:",round(aa$r.squared,3)),cex = .8)
  #plot(density(resid(reg)))
  plots[[i]] <- p1

}
grid.arrange(grobs = plots[1:15], ncol=5)

OR

do.call(grid.arrange, c(plots, ncol=3))

grid.arrange requires grid-based graphics. base plot() doesn't return anything. You probably should look into split.screen , layout , par(mfrow=...) . Alternatively (as last resort) look at the gridBase or gridGraphics package for ways to combine the two systems.

链接地址: http://www.djcxy.com/p/30882.html

上一篇: 使用ggmap和plotRGB将多个图像一起绘制

下一篇: 在一个页面grid.arrange函数中添加多个图