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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:16:20+00:00 2026-06-09T02:16:20+00:00

I can use ggplot2 to store the output of ggplot command to an object

  • 0

I can use ggplot2 to store the output of ggplot command to an object and call that object within grid.arrange to write to a file in an R script, as below:

p<-ggplot(x, aes(x=Date, y=Date)) + geom_bar(aes(x=Date,y=Data)

png("data.png", height=700, width=650)

grid.arrange(p, main=textGrob("Data"), gp=gpar(cex=2)               

dev.off()

I am creating bunch of forecast graphs using plot but I cannot do the same thing. Any one has any suggestion how can I write the ouput of plot to a png file in a script?

  • 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-09T02:16:22+00:00Added an answer on June 9, 2026 at 2:16 am

    We don’t have data to work with and the questions not clear so here’s an example of what I think the OP is after (separate plots for each plot) using the mtcars data set:

    dat <- split(mtcars, mtcars$cyl)
    
    lapply(dat, function(x) {
        ggplot(x, aes(mpg, disp, colour=gear)) + geom_point()
        }
    )
    
    #a way to get separate plots for each plot
    plot2 <- function(theplot, name, ...) {
        name <- paste0(name, ".png")
        png(filename=name)
        print(theplot)
        dev.off()
    } #plotting function
    
    lapply(seq_along(dat), function(i) {
        x <- dat[[i]]
        z <- ggplot(x, aes(mpg, disp, colour=gear)) + geom_point()
        plot2(z, name=paste0("TEST", names(dat)[i]))
        }
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With grid.arrange I can arrange multiple ggplot figures in a grid to achieve a
I know that after I create a ggplot graph I can use theme_get() to
I can use this maven plugin maven-jaxb-plugin to generate Java Classes from XSD file.
Can I use ggplot2 to produce a violin plot? Perhaps using some variation of
Can I use subscripts in ggplot2 legends? I see this question on greek letters
You can use a standard dot notation or a method call in Objective-C to
What function can I use to emulate ggplot2's default color palette for a desired
I can use the following to get the contents of a folder with no
Users can use their Google, Facebook or Twitter account to login to a site
I can use .button() to create beautiful submit buttons, but the rest 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.