Figure A2-4: A Pairs Plot

Portfolio Categories: All Graphics and SGR Book Graphics.

A Default Pairs Plot of the Built-in R Trees Data

A Pairs Plot of the Built-In R Trees Data


# We'll use the built-in trees data.  For demonstration purposes we'll just
# use the first 26 observations and add a character variable using the 
# built-in LETTERS vector (A-Z)

myTrees = trees[1:26,]                 # Use the first 26 observations
myTrees$treeID = LETTERS               # Add a letter ID for each obs
myTrees$even =                         # Add a factor variable for even and
  as.factor(c("even", "odd"))          #   odd observations

# pairs plot -------------------------------------------------------------------

png(filename = "illustrations/fig-AII-4-pairs plot.png",
  units = "in",                        # Set measurements in inches
  res = 1200,                          # Set resolution at 1200dpi
  width = 6,                           # Width at 6 inches
  height = 4)                          # Height at 4 inches

par(mai = c(0, 0, 0, 0))               # Set margins

pairs(myTrees[-c(4, 5)])               # Pairs to produce bivariate plots

dev.off()                              # Output png file