Graphics Reference
In-Depth Information
Figure 13-36. With a diverging color scale
The previous example mapped continuous values to fill , but we could just as well use discrete
values. It's sometimes easier to interpret the data if the values are discretized. For example, we
can categorize the values into quantiles and show those quantiles, as in Figure 13-37 :
# Find the quantile bounds
qa <- quantile(crimes$Assault, c( 0 , 0.2 , 0.4 , 0.6 , 0.8 , 1.0 ))
qa
0 % 20 % 40 % 60 % 80 % 100 %
45.0 98.8 135.0 188.8 254.2 337.0
# Add a column of the quantile category
crimes$Assault_q <- cut(crimes$Assault, qa,
labels = c( "0-20%" , "20-40%" , "40-60%" , "60-80%" , "80-100%" ),
include.lowest = TRUE
TRUE )
crimes
state Murder Assault UrbanPop Rape Assault_q
Alabama alabama
13.2
236
58 21.2
60 - 80 %
Alaska alaska
10.0
263
48 44.5
80 - 100 %
...
Wisconsin wisconsin
2.6
53
66 10.8
0 - 20 %
Wyoming wyoming
6.8
161
60 15.6
40 - 60 %
Search WWH ::




Custom Search