Graphics Reference
In-Depth Information
library(gcookbook)
# For the data set
library(plyr)
# For the ddply() function
# Convert Thousands to Percent
uspopage_prop
<-
ddply(uspopage,
"Year"
, transform,
Percent
=
Thousands
/
sum(Thousands)
*
100
)
Once we've calculated the proportions, plotting is the same as with a regular stacked area graph
(
Figure 4-24
)
:
ggplot(uspopage_prop, aes(x
=
Year, y
=
Percent, fill
=
AgeGroup))
+
geom_area(colour
=
"black"
, size
=
.2
, alpha
=
.4
)
+
scale_fill_brewer(palette
=
"Blues"
, breaks
=
rev(levels(uspopage$AgeGroup)))
Figure 4-24. A proportional stacked area graph
Discussion
Let's take a closer look at the data and how it was summarized:
uspopage
Year AgeGroup Thousands
1900
<
5
9181