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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:48:38+00:00 2026-05-26T06:48:38+00:00

I would like to make a series of plots using ggplot from multiple different

  • 0

I would like to make a series of plots using ggplot from multiple different dataframes. I was planning on using a list and iterating over the list as follows:

libraries <- objects() #make a list of the dataframes we want to graph
for(i in libraries) {
  # create initial plots
  x1 <- qplot(data= i, V1, reorder(V2,V3), color = V3) + coord_flip()
  x2 <- ggplot(i, aes(x=reorder(V2,V3), group=V3, color=V3)) + geom_bar() 
  x3 <- ggplot(i, aes(x=V1, group=V3, color=V3)) + coord_flip() + geom_bar()
}

however I get the error message:

Error: ggplot2 doesn't know how to deal with data of class factor

presumably because ‘libraries’ is now a character variable and not a data frame. Any one have another suggestion on how to iterate through the dataframes? I suppose I could merge them with plyr and then ggplot a subset of the data but that seems to add more work.

  • 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-26T06:48:39+00:00Added an answer on May 26, 2026 at 6:48 am

    The usual way to iterate over data.frames (which are just regularly organized lists) is with lapply:

     df1 <- data.frame(date = as.Date(10*365*rbeta(100, .5, .1)),group="a")
      df2 <- data.frame(date = as.Date(10*365*rbeta(50, .1, .5)),group="b")
      df3 <- data.frame(date = as.Date(10*365*rbeta(25, 3,3)),group="c")
      dfrmL <- list(df1,df2,df3)
    
     lapply(dfrmL, NROW)
    [[1]]
    [1] 100
    
    [[2]]
    [1] 50
    
    [[3]]
    [1] 25
    

    In the case of producing a list of ggplot-objects I would imagine that the Hadley-method would instead be to use llply, but I’m not a skilled plyr-user, so let me suggest this totally untested code template:

    plts <- lapply(dfrmL, function(df) qplot(qplot(data= df, 
                                              V1, reorder(V2,V3), color = V3) + 
                                      coord_flip()
           )  
     # you may need to explicitly print() or plot() the plots as stated in the R-FAQ.    
    lapply(plts, print)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to make a series of histograms from columns in a dataframe
I would like to make an ajax call to a different server (same domain
I would like to make a list of remarkable robot simulation environments including advantages
I would like to make my application somewhat REST compliant. I am using Rails
I would like to make sure that a series of commands are executed in
I would like to generate a TSV file from a list of vehicles....I'll also
I would like make an extension method for the generic class A which takes
Would like to make anapplication in Java that will not automatically parse parameters used
I would like to make a nightly cron job that fetches my stackoverflow page
I would like to make a child class that has a method of the

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.