Graphics Reference
In-Depth Information
The text under the circles is in a shade of grey. This is so that it doesn't jump out at the viewer
and overwhelm the perceptual impact of the circles, but is still available if the viewer wants to
know the exact values.
See Also
To add labels to the circles, see Recipes and .
See Mapping a Continuous Variable to Color or Size for ways of mapping variables to other aes-
thetics in a scatter plot.
Making a Scatter Plot Matrix
Problem
You want to make a scatter plot matrix.
Solution
A scatter plot matrix is an excellent way of visualizing the pairwise relationships among several
variables. To make one, use the pairs() function from R's base graphics.
For this example, we'll use a subset of the countries data set. We'll pull out the data for the
year 2009, and keep only the columns that are relevant:
library(gcookbook) # For the data set
c2009 <- subset(countries, Year == 2009 ,
select = c(Name, GDP, laborrate, healthexp, infmortality))
c2009
Name GDP laborrate healthexp infmortality
Afghanistan
NA
59.8
50.88597
103.2
Albania
3772.6047
59.5 264.60406
17.2
Algeria
4022.1989
58.5 267.94653
32.0
...
Zambia
1006.3882
69.2
47.05637
71.5
Zimbabwe
467.8534
66.8
NA
52.2
To make the scatter plot matrix ( Figure 5-36 ), we'll use columns 2 through 5—using the Name
column wouldn't make sense, and it would produce strange-looking results:
pairs(c2009[, 2 : 5 ])
 
 
Search WWH ::




Custom Search