Grid of Graphics#
We often wish to show 2 or more graphical displays for a specific data set while minimizing the space required to do so. We will use two functions to assist us:
layout()
matrix()
Warning
We use the option lcm() to specify the height of the graphical display in centimeters. Values between 5 and 12 generally work well, and some guesswork is typically required.
Tip
We create a plot called plt because it’s made up of 2 different graphical pieces: the qqnorm plot and qqline superimposed on top. Since we wish to display these 2 elements together, we surround them with { } and store them as the single graphical item plt.
For an example, let’s display a histogram and a QQ plot for the naricissism variable of the personality data frame:
pers <- read.csv('https://faculty.ung.edu/rsinn/data/personality.csv')
data <- pers[ , 'Narc']
# Using layout() and matrix() to create grid.
layout(matrix(c(1,2), ncol = 2), lcm(8))
hist(data)
plt <- { qqnorm(data, main = 'QQ Plot: Narcissism') ; qqline(data, col = 'blue') }
