BIOS 591R - 2019 - Lecture 8: Graphics I: base graphics

Ziyi Li <ziyi.li@emory.edu>

Content today

  • Features and history of R graphics
  • Brief overview of BASE graphics

Features of R graphics

  • R has a powerful environment for visualization of scientific data
  • It provides publication quality graphics, which are fully programmable
  • Easily reproducible
  • Full LaTeX and Sweave support
  • Lots of packages and functions with built-in graphics support
  • On-screen graphics
  • Postscript, PDF, jpeg, png, SVG

History of R graphics

History of R graphics

R graphics can be confusing because there are no less than 4 different systems. Let's list them out here and talk about which one(s) to use.

Low-Level Capability

  • Base Graphics (Has Low and High Level functions)
  • Grid Graphics

High-Level Capability

  • Lattice Graphics
  • ggplot2

History: BASE graphics

  • Oldest and most commonly used
  • Uses a “pen-on-paper” model. You can only draw on top of the object. Cannot erase, modify, or delete what has already been drawn. Mimicing the thinking process.
  • Has both high and low level plotting routines (unique to Base)
  • Base graphics are fast.
  • Lots of documentation and “google” support

BASE graphics

History: Grid graphics

  • Developed in 2000 by Paul Murrell
  • Provides a rich set of graphics primitives
  • Uses a system of objects and view ports to make complex objects easier.
  • You will almost never use this directly unless you want to do in-depth programming

Grid graphics

History: Lattice package

  • Developed by Deepayan Sarkar to implement the trellis graphics system described in “Visualizing Data” by Cleveland.
  • Independent from the BASE graphics. Include its own functions such as xyplot, bwplot, levelplot
  • Easy to create conditioned plots with automatic creation of axes, legends, and other annotations
  • Usually considered to be an improvement over Base graphics.

Lattice package

library(lattice)
xyplot(mpg~wt | factor(am,labels=c("Auto","Manual")), data=mtcars)

plot of chunk unnamed-chunk-1

History: ggplot2

  • Developed starting in 2005 by Hadley Wickham
  • ggplot2 is an implementation of Leland Wilkinson's Grammar of Graphics–a general scheme for data visualization which breaks up graph into semantic components such as scales and layers.
  • ggplot2 can serve as a replacement for the base graphics in R and contains a number of defaults for web and print display of common scales.
  • Is said to be much slower than Base graphics but this isn't a major thing (in my opinion)
  • Part of Tidyverse

ggplot2

BASE Graphics

Brief overview of BASE graphics

Brief overview of BASE graphics

Brief overview of BASE graphics

Brief overview of BASE graphics

Brief overview of BASE graphics