【发布时间】:2015-03-03 13:50:44
【问题描述】:
我正在运行 R 版本 3.1.1。在 RStudio 中,并且在使用 grid.arrange 时遇到了困难。
我正在阅读 100 多家商店的销售数据并绘制一段时间内的销售情况。我还尝试将图分组以一次显示一组数字。
然而,经过多次不同的尝试,命令
do.call("grid.arrange", c(plotlist, ncol=nCol))
导致绘图矩阵中的所有绘图都相同。此外,从绘图列表中绘制单个项目表明所有绘图也作为相同的元素存储在绘图列表中。
这里是重复问题的代码:
require(ggplot2)
require(gridExtra)
wss <- data.frame(ind=1:10, dep=(1:10))
plotlist <- list()
for (i in 1:4) {
wss <- data.frame(ind=wss$ind, dep=(i*wss$dep))
plotname <- paste0("Store", i, sep="")
plotlist[[ plotname ]] <- ggplot(data=wss, aes(x=wss$ind, y=wss$dep)) + geom_line() + theme_bw() + ggtitle(paste0("Store #",i, sep="")) + ylab("Sales Revenue") + theme(axis.title.x=element_blank())
}
n <- length(plotlist)
nCol <- floor(sqrt(n))
do.call("grid.arrange", c(plotlist, ncol=nCol))
【问题讨论】:
标签: plot duplication