使用ggplot2绘制一页上的绘图列表

时间:2018-01-02 19:47:41

标签: r plot ggplot2 shiny

我需要你的帮助,因为我不知道如何解决我的问题。我有我的闪亮应用程序,我有数据框(从文件导入)和checkboxgroupinput我可以标记哪些列对我来说很有趣。问题是有趣列的数量不是恒定的。我想将所有情节放在一个页面上,所以我决定将所有情节保存到列表中。但现在我不知道如何将它们全部绘制出来。 我找到了功能:

  multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {
  require(grid)
  plots <- c(list(...), plotlist)
  numPlots = length(plots)

  if (is.null(layout)) {
    layout <- matrix(seq(1, cols * ceiling(numPlots/cols)), ncol = cols, nrow = ceiling(numPlots/cols))
  }

  if (numPlots==1) {
    print(plots[[1]])
  } 
  else {
    grid.newpage()
    pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))
    for (i in 1:numPlots) {
      matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))
      print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row, layout.pos.col = matchidx$col))
    }
  }
}

我知道我可以使用它:

multiplot(plot[[1]], plot[[2]],...,plot[[n]], cols = 2)

但是,如果我不知道数字n,我怎么画它?

multiplot(plot, cols = 2)

不起作用:/任何提示?

0 个答案:

没有答案