Skip to main content Skip to navigation

Graphics devices

R Graphics Devices

Types:

  • Screen devices. Platform dependent. Includes x11(), quartz(), windows() etc.
  • File devices:
    • bitmap:  png() tiff() jpeg()
    • vector drawing:  pdf() postscript() svg()
    • LaTeX source:  tikz()

Bitmap (or raster) file formats

  • these do not scale well; they can look "blurred" and "blocky" when viewed or printed.
  • .png is nonetheless useful for web display, pixel editing with GIMP etc.
  • .tiff is still (?) insisted upon by some old-school print shops?
png(file = "mygraph.png")
curve(dnorm, -5, 5)
dev.off()

mygraph.png

Scalable (i.e., 'vector') file formats

The main ones to know about are:

  • .pdf --- Portable Document Format; not easily editable, but very portable
  • .eps --- Encapsulated PostScript; an older page description languade from Adobe. Still insisted upon by some print shops, who use Adobe Illustrator.
  • .svg --- Scalable Vector Graphics; an open standard, using XML. Rendered by most modern web browsers. Hand-editable using Inkscape etc.
svg(file = "mygraph.svg")
curve(dnorm, -5, 5)
dev.off()

mygraph.svg

Graphs as LaTeX source code

The tikz package for LaTeX allows graphs to be drawn using TeX primitives. Builds upon the earlier pictex package (for plain TeX; written by Michael Wichura, Dept of Statistics, University of Chicago).

library(tikzDevice)       ##  a contributed package on CRAN

tikz(file = "mygraph.tex", standAlone = TRUE, width = 5, height = 4) ## there are plenty of useful options
curve(dnorm, -5, 5, xlab = "$x$", ylab = "$\\phi(x)$")
text(2.5, 0.3, "$\\phi(x)={1\\over \\sqrt{2\\pi}}e^{-x^2/2}$")
dev.off()

mygraph.pdf


The coolest graphics device?

  • whatever works best for the graph you want to draw!
  • 3-D printed surface plots??
  • and my personal favourite