0
我繪製了15個包含迴歸線的散點圖。不過,我想在一個頁面上展示以更好地形象化。 grid.arrange函數有助於根據我們的興趣添加多個圖,但是我總是面對一個錯誤。在一個頁面上添加多個圖格.arrange函數
錯誤爲Glist(列表(wrapvp =列表(x = 0.5,Y = 0.5,寬度= 1,高度= 1,: 僅在 「爲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)
'grobs' OR
do.call(grid.arrange, c(plots, ncol=3))
我在編輯刪除錯誤的標籤。 –