Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7967011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:35:07+00:00 2026-06-04T06:35:07+00:00

library(ggplot2) df <- data.frame(x=1:10, y=rnorm(10)) p1 <- ggplot(df, aes(x,y)) + geom_point() plist <- list(p1,p1,p1,p1,p1)

  • 0
library(ggplot2)
df <- data.frame(x=1:10, y=rnorm(10))
p1 <- ggplot(df, aes(x,y)) + geom_point()
plist <- list(p1,p1,p1,p1,p1)
# In my real example,a plot function will fit a ggplot to a list of datasets 
#and return a list of ggplots like the example above.

I’d like to arrange the plots using grid.arrange() in gridExtra.

How would I do this if the number of plots in plist is variable?

This works:
grid.arrange(plist[[1]],plist[[2]],plist[[3]],plist[[4]],plist[[5]])

but I need a more general solution. thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:35:08+00:00Added an answer on June 4, 2026 at 6:35 am

    How about this:

    library(gridExtra)
    n <- length(plist)
    nCol <- floor(sqrt(n))
    do.call("grid.arrange", c(plist, ncol=nCol))
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I plot the following: library(ggplot2) carrots <- data.frame(length = rnorm(500000, 10000, 10000)) cukes <-
I have the following plot: library(ggplot2) ib<- data.frame( category = factor(c(Cat1,Cat2,Cat1, Cat1, Cat2,Cat1,Cat1, Cat2,Cat2)),
library(ggplot2) This code produces a nice looking plot: qplot(cty, hwy, data = mpg, colour
When running this code (go ahead, try it): library(ggplot2) (myDat <- data.frame(cbind(VarX=10:1, VarY=runif(10)), Descrip=sample(LETTERS[1:3],
I have written the following code: library(ggplot2) data <- structure(list(x = c(1L, 6L, 3L,
The following commands library(ggplot2) ggplot(PlantGrowth, aes(x=group, y=weight)) + geom_boxplot() produce this graph. . I
library(ggplot2) my_title = This is a really long title of a plot that I
I have the following function, which I would like to plot using ggplot: f(x)
Suppose I draw the following plot composed of two polygons : library(ggplot2) polys <-
I am using ggplot2 to plot simple line charts of time series data. One

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.