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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:03:36+00:00 2026-05-25T02:03:36+00:00

I plot a simple linear regression using R. I would like to save that

  • 0

I plot a simple linear regression using R.
I would like to save that image as PNG or JPEG. Is it possible to do it automatically? (via code)

There are two different questions: First, I am already looking at the plot on my monitor and I would like to save it as is. Second, I have not yet generated the plot, but I would like to directly save it to disk when I execute my plotting code.

  • 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-25T02:03:37+00:00Added an answer on May 25, 2026 at 2:03 am

    There are two closely-related questions, and an answer for each.


    1. An image will be generated in future in my script, how do I save it to disk?

    To save a plot, you need to do the following:

    1. Open a device, using png(), bmp(), pdf() or similar
    2. Plot your model
    3. Close the device using dev.off()

    Some example code for saving the plot to a png file:

    fit <- lm(some ~ model)
    
    png(filename="your/file/location/name.png")
    plot(fit)
    dev.off()
    

    This is described in the (combined) help page for the graphical formats ?png, ?bmp, ?jpeg and ?tiff as well as in the separate help page for ?pdf.

    Note however that the image might look different on disk to the same plot directly plotted to your screen, for example if you have resized the on-screen window.


    Note that if your plot is made by either lattice or ggplot2 you have to explicitly print the plot. See this answer that explains this in more detail and also links to the R FAQ: ggplot's qplot does not execute on sourcing


    2. I’m currently looking at a plot on my screen and I want to copy it ‘as-is’ to disk.

    dev.print(pdf, 'filename.pdf')
    

    This should copy the image perfectly, respecting any resizing you have done to the interactive window. You can, as in the first part of this answer, replace pdf with other filetypes such as png.

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

Sidebar

Related Questions

I would like to plot a simple interval on the number line in Mathematica.
I would like to plot a simple graphic. I have a dat set with
I would like to create a simple flow chart in latex with the TikZ
I'm wanting to write a simple WinForms application that will be able to plot
I have a cherryPy program that returns a page that has an image (plot)
In my work, I frequently display scatterplots using text labels. That's meant a plot()
I'm using GD to plot some simple charts from array point data.. Trying to
I would like to plot how the amplitude and orientation of a 2D vector
So I'd like to plot simple gamma function, but I have some problems. My
I am using tkinter to write a simple GUI program to plot figure of

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.