Save Graphs to Files

R Graphical Devices

  • The following devices are currently available:

    • PDF – Write PDF graphics commands to file.
    • xfig – Device for XFIG graphics file format.
    • pictex – Writes TeX/PicTeX graphics commands to a file (of historical interest only).
    • postscript – Writes PostScript graphics commands to a file.
    • bitmap – bitmap pseudo-device via Ghostscript (if available).
    • SVG – Device for the SVG File Format
    • libgd – Supports fast image creation
    • GTK – Supports gtkDevice.
    • quartz – Graphics Device Driver for MacOS.
    • x11 – Provides functions in Windows for opening interactive graphics device.
  • The following devices will be functional if R is compiled to use them:

    • png – PNG bitmap device
    • jpeg – JPEG bitmap device
    • bmp – BMP bitmap device
    • tiff – TIFF bitmap device
    • X11 – This is for the X11 windowing system.
    • svg – SVG device based on Cairo graphics.
    • cario.pdf, – cairo_ps PDF and PostScript devices based on Cairo graphics.
    • quartz – The graphics device for the macOS native Quartz 2d graphics system.
setwd("~/")
getwd()
data("mtcars")
scatter <- mtcars[,c('wt','mpg')]
#Naming the file
png(file = "DataFlair_plot.png")
#Creating our Scatterplot
plot(x = scatter$wt,y = scatter$mpg,
     xlab = "Weight",
     ylab = "Mileage",
     xlim = c(2.5,5),
     ylim = c(15,30), 
     main = "Weight vs Mileage"
     )

dev.off() #Saving the file

Reference:

results matching ""

    No results matching ""