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 7524763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:09:03+00:00 2026-05-30T03:09:03+00:00

as a new ggplot2 user, I am a bit lost with the amount of

  • 0

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 like to display multiple plots from ggplot2 on a same sheet, BUT knowing that these plots come from a for loop.

Following example does not compile, it is only to illustrate :

for(i in c(1:n)){                                   
  for(j in c(1:m)){
    ..........  # some data production
    p <- ggplot(df.all) + geom_bar(aes_string(x=class.names[i],fill=var.names[j])
}}

Here, p is overwritten, but I would like to have instead a matrix or a list in which I can put all the p as they are produced, then a simple function like

display_in_a_grid(list_of_ggplot_plots)

But as far as I tried, I was not able to make a list of matrix of plot, neither to find a function that takes only one argument for input.

About things I have had a look at :

“arrangeGrob” from package gridExtra doesn’t work because it requires an explicit name for each plot (e.g.: p1,p2,p3,…) like in http://code.google.com/p/gridextra/wiki/arrangeGrob

“facet” method of ggplot2 is not adapted to the organization of my data set (or the contrary :p )

Would you have a simple way to manage this ?

Thank you,

François

  • 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-05-30T03:09:05+00:00Added an answer on May 30, 2026 at 3:09 am

    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)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(New to ASP.NET here.) I have a user control which should check for a
New to .NET, any point in the right direction would be a huge help.
I'm new to ggplot2 and would like to plot lines in an existing plot
New day, new problem :-) Code: Client Side: void abw_Closed(object sender, EventArgs e) {
I am new to Sweave/Tex and would like to keep my R code out
NEW EDIT: I have narrowed my problem to this - i have a view
New to Javascript and jQuery, so I assume this is a pretty simple question.
New to .NET/C# stuff so please forgive me if it's something obvious ;-) I'm
New to scala and can't seem to find a reference on this situation. I'm
I am quite new to ggplot2, so forgive me if this post is too

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.