Chapter 11. Rug Plots

The Rug Plot

The rug is not really a separate plot. It is a one-dimensional display that you can add to existing plots to illuminate information that is sometimes lost in other types of graphs. Like a strip plot, it represents values of a variable by putting a symbol at various points along an axis. However, it uses short lines to represent points. You can place it at the bottom (the default) or top of a graph (side = 3). If appropriate—for example, if a box plot is vertical—the rug can be put on the left (side = 2) or right (side = 4) axis. When two observations have the same value, they are overprinted, so that the line is darker. Here are some examples:

# Script for Figure 11-1
library(multcomp)
par(mfrow = c(2,2))
stripchart(mtcars$drat,
  main="a. side = 3", method = "jitter",
  pch = 20, col = "sienna4")
rug(mtcars$drat, side = 3)

boxplot(mtcars$drat, main = "b. side = 2",
  col = "firebrick")
rug(mtcars$drat, col = "darkmagenta", side = 2)

hist(airquality$Ozone, main = "c. side = 1", col = "cyan4")
rug(airquality$Ozone, col = "cyan4")


boxplot(sbp$sbp,
  main = "d. side = 4", col = "darkorange3")
rug(sbp$sbp, side = 4, col = "cornsilk4")

The preceding script produces the plots in Figure 11-1.

Uses of the rug plot.
Figure 11-1. Uses of the rug plot.

Figure 11-1a shows that adding a rug is essentially like putting a strip chart at the bottom or top of another graph. This is not ...

Get Graphing Data with R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.