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

  • Home
  • SEARCH
  • 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 3980414
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:17:16+00:00 2026-05-20T05:17:16+00:00

A previous post provided a solution to iteratively store plots in R: see …

  • 0

A previous post provided a solution to iteratively store plots in R: see … iteratively in R… . I had a similar problem and after reading and implementing the solutions provided by the post I am still unable to solve my problem.

The previous post provided the following code:

# Create a list to hold the plot objects.

pltList <- list()

for( i in 2:15 ){

# Get data, perform analysis, ect.

# Create plot name.
pltName <- paste( 'a', i, sep = '' )

# Store a plot in the list using the
name as an index.
pltList[[ pltName ]] <- plot()

}

The following is my code implementation:

a <- list.files("F:.../4hrs", pattern='.csv')
pltList <- list()
i=1

for (x in a) {
    myfiles <- read.csv(a, header=TRUE, as.is=TRUE, nrows=2500)

    h <- hist(data, plot=F)
    # perform analysis, ect.

    pltName <- paste('a', formatC(i, width=2, flag='0'), sep='')
    pltList[[ pltName ]] <- plot(h)
    i <- i+1

  }

pltName does produce a list of names but pltList is of length zero.

I am not sure why pltList is not being assigned the plots.
What I eventually want to do is create a pltList with multiple plots contained therein. Then plot those plots in par(mfrow=c(2,1)) style and export as a .pdf.

I should mention that the above works for

pltList[[ pltName ]] <- xyplot(h)

but then I am unable to plot multiple plots in the style of par(mfrow=c(2,1)).

Any suggestions are appreciated.

  • 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-20T05:17:17+00:00Added an answer on May 20, 2026 at 5:17 am

    In the original question you referenced and my answer to it, plot() was used as an abstract placeholder for a plotting function that returned an object and not a literal call to the R function plot. Most functions that return graphics objects are based on the ‘grid’ package such as xyplot from the lattice package or qplot from ggplot2.

    Sorry for the confusion, I should have made this point clear in my answer, but I did not as the asker of the question was already aware of it.

    Base graphics functions such as hist and plot render directly to output and do not return any objects that can be used to recreate the plot at a later time which is why you are ending up with a list of length zero.

    In order to use this approach you will have to trade usage of the hist function for something that returns an object. Using ggplot2, you could do something like the following in your loop:

    # Don't call your data variable 'data' or ggplot will confuse it with the
    # `data` function and suffer an error.
    h <- qplot(x = plot_data)
    
    pltName <- paste('a', formatC(i, width=2, flag='0'), sep='')
    pltList[[ pltName ]] <- h
    

    I have edited my answer to the previous question to make it clear that the use of plot() in my example is not an actual call to the R function of the same name.

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

Sidebar

Related Questions

After seeing a previous post Making Applications programmed in .NET languages work on older
After I messed up the description of my previous post on this I have
I'm experiencing the same problem in this previous stackoverflow.com post . Specifically, I seem
Thanks for the help on my previous post, @AndyE, your solution works great. now
Ok after my previous post, i have made some progress, yet still i need
This question is related to a previous post of mine Here . Basically, I
As an addition to my previous post on Creating a web server in pure
I have this function from a plugin (from a previous post) // This method
I've been doing some reading on mysqli_real_escape_string(), and, after getting my content properly escaped,
This post is related to my Previous Post . There I was creating 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.