R graphics

Data Visualisation with R

Graphics 🖼️

  • Graphics are commonly stored in a standard image format such as svg, jpg (or jpeg), png, pdf, and so on.
  • When you view these graphics electronically, you would be using some graphical device to render the stored image.
  • In R, the graphic is rendered by the graphical engine, grDevices (one of the core R package).

Graphics model in R

  • Two main graphics model in R are implemented via two core packages:
    • graphics package, and
    • grid package.
  • Plot using the graphics system is normally referred to as the base graphics.
  • If the graphics is produced using the grid package, then it is using the grid graphics model.

Base graphics

  • Base graphics are drawn via the graphics package and shown in display via the grDevices package

grid graphics

  • The grid package contains low-level functions, i.e. draws only parts of the plot.
  • This system gives a lot of control over the graphics, but requires the user to do a lot of work to draw a complete plot.
  • You won’t be directly interacting with the grid package.
  • Instead you’ll be using the ggplot2 package that provides high-level functions for plotting via the grid system.

Other graphical systems

  • All other graphical systems are provided via contributed packages (i.e. you need to install it once to use it).
  • The two most well known packages are:
    • lattice and
    • ggplot2.
  • Both of these packages use the grid package to draw the plots.

Summary of R graphics