3.how To Save A Plot (As Bitmap, Vector Image, PDF, PostScript) in R
3.how To Save A Plot (As Bitmap, Vector Image, PDF, PostScript) in R
Interested
Search in Data Science? Get Started With Data Science in R.
tutorials...
Sign Up Now
Saving a Plot in R
In this article, you’ll learn to save plots in R programming. You’ll learn to save plots as
bitmap and vector images.
All
the graphs (bar plot, pie chart, histogram, etc.) we plot in R programming are
displayed on the screen by default.
We can save these plots as a le on disk with the help of built-in functions.
It is important to know that plots can be saved as bitmap image (raster) which are
xed size or as vector image which are easily resizable.
https://www.datamentor.io/r-programming/saving-plot/ 1/7
10/16/2019 How to save a plot (as Bitmap, Vector Image, PDF, PostScript) in R?
jpeg(file="saving_plot1.jpeg")
hist(Temperature, col="darkgreen")
dev.off()
This will save a jpeg image in the current directory. The resolution of the image by
default will be 480x480 pixel.
https://www.datamentor.io/r-programming/saving-plot/ 2/7
10/16/2019 How to save a plot (as Bitmap, Vector Image, PDF, PostScript) in R?
png(file="C:/Datamentor/R-tutorial/saving_plot2.png",
width=600, height=350)
hist(Temperature, col="gold")
dev.off()
The following code saves a bmp le of size 6x4 inch and 100 ppi.
bmp(file="saving_plot3.bmp",
width=6, height=4, units="in", res=100)
hist(Temperature, col="steelblue")
dev.off()
https://www.datamentor.io/r-programming/saving-plot/ 3/7
10/16/2019 How to save a plot (as Bitmap, Vector Image, PDF, PostScript) in R?
tiff(file="saving_plot3.tiff",
width=6, height=4, units="in", res=100)
hist(Temperature, col="steelblue")
dev.off()
Save as pdf le
To save a plot as pdf we do the following.
https://www.datamentor.io/r-programming/saving-plot/ 4/7
10/16/2019 How to save a plot (as Bitmap, Vector Image, PDF, PostScript) in R?
pdf(file="saving_plot4.pdf")
hist(Temperature, col="violet")
dev.off()
Save as postscript le
Similarly, to save the plot as a postscript le, we change the rst line to
postscript(file="saving_plot4.ps") .
postscript(file="saving_plot4.ps")
hist(Temperature, col="violet")
dev.off()
« PREVIOUS
R MULTIPLE PLOTS
NEXT
R PLOT COLOR »
R TUTORIAL
R Introduction
R Flow Control
R Functions
R Data Structure
R Advanced Topics
-- R Programming Subplot
https://www.datamentor.io/r-programming/saving-plot/ 5/7
10/16/2019 How to save a plot (as Bitmap, Vector Image, PDF, PostScript) in R?
-- R Programming Color
-- R Programming 3D Plot
Learn more
DATAMENTOR
COURSES
RESOURCES
R Tutorials
R Examples
COMPANY
About Us
Adver tising
Contact Us
https://www.datamentor.io/r-programming/saving-plot/ 6/7
10/16/2019 How to save a plot (as Bitmap, Vector Image, PDF, PostScript) in R?
LEGAL
Privacy Policy
https://www.datamentor.io/r-programming/saving-plot/ 7/7