Graphics Reference
In-Depth Information
See Also
For more on controlling the appearance of the text, see Changing the Appearance of Text .
If you want to manually edit a PDF or SVG file, see Editing a Vector Output File .
Creating a Balloon Plot
Problem
You want to make a balloon plot, where the area of the dots is proportional to their numerical
value.
Solution
Use geom_point() with scale_size_area() . For this example, we'll use a subset of the
countries data set:
library(gcookbook) # For the data set
cdat <- subset(countries, Year == 2009 &
Name %in% c( "Canada" , "Ireland" , "United Kingdom" , "United States" ,
"New Zealand" , "Iceland" , "Japan" , "Luxembourg" ,
"Netherlands" , "Switzerland" ))
cdat
Name Code Year GDP laborrate healthexp infmortality
Canada CAN 2009 39599.04
67.8 4379.761
5.2
Iceland ISL 2009 37972.24
77.5 3130.391
1.7
Ireland IRL 2009 49737.93
63.6 4951.845
3.4
Japan JPN 2009 39456.44
59.5 3321.466
2.4
Luxembourg LUX 2009 106252.24
55.5 8182.855
2.2
Netherlands NLD 2009 48068.35
66.1 5163.740
3.8
New Zealand NZL 2009 29352.45
68.6 2633.625
4.9
Switzerland CHE 2009 63524.65
66.9 7140.729
4.1
United Kingdom GBR 2009 35163.41
62.2 3285.050
4.7
United States USA 2009 45744.56
65.0 7410.163
6.6
If we just map GDP to size , the value of GDP gets mapped to the radiusof the dots ( Figure 5-34 ,
left), which is not what we want; a doubling of value results in a quadrupling of area, and this
will distort the interpretation of the data. We instead want to map it to the area, and we can do
this using scale_size_area() ( Figure 5-34 , right):
Search WWH ::




Custom Search