Plotting Systems

There are three different plotting systems in R and they each have different characteristics and modes of operation. They three systems are the base plotting system, the lattice system, and the ggplot2 system. This chapter (and this book) will focus primarily on the base plotting system.

The BASE Plotting System

data(airquality)
 with(airquality, {
 plot(Temp, Ozone)
 lines(loess.smooth(Temp, Ozone))
 })

# Load the cars data
data(cars)

## Create the plot / draw canvas
with(cars, plot(speed, dist))

## Add annotation
title("Speed vs. Stopping distance")

The Lattice System

library(lattice)

state <- data.frame(state.x77, region = state.region)
xyplot(Life.Exp ~ Income | region, data = state, layout = c(4, 1))

The ggplot2 System

library(ggplot2)

data(mpg)

qplot(displ, hwy, data = mpg)