Grid of multiple ggplot2 plots which have been made in a for loop

后端 未结 2 571
难免孤独
难免孤独 2020-11-29 23:57

as a new ggplot2 user, I am a bit lost with the amount of possibilities, and struggle to find on the net a simple answer to what I consider a simple problem.

I would

2条回答
  •  不知归路
    2020-11-30 00:30

    I would be inclined to agree with Richie, but if you want to arrange them yourself:

    library(gridExtra)
    library(ggplot2)
    p <- list()
    for(i in 1:4){
      p[[i]] <- qplot(1:10,10:1,main=i)
    }
    do.call(grid.arrange,p)
    

    take a look at the examples at the end of ?arrangeGrob for ways to eliminate the for loop altogether:

    plots = lapply(1:5, function(.x) qplot(1:10,rnorm(10),main=paste("plot",.x)))
    require(gridExtra)
    do.call(grid.arrange,  plots)
    

提交回复
热议问题