Graphics Reference
In-Depth Information
1900
25
-
34
12161
1900
35
-
44
9273
1900
45
-
54
6437
1900
55
-
64
4026
1900
>
64
3099
1901
<
5
9336
1901
5
-
14
17158
...
The default order of legend items is the opposite of the stacking order. The legend can be re-
versed by setting the breaks in the scale. This version of the chart (
Figure 4-21
) reverses the le-
gend order, changes the palette to a range of blues, and adds thin (
size=.2
) lines between each
area. It also makes the filled areas semitransparent (
alpha=.4
), so that it is possible to see the
grid lines through them:
ggplot(uspopage, aes(x
=
Year, y
=
Thousands, fill
=
AgeGroup))
+
geom_area(colour
=
"black"
, size
=
.2
, alpha
=
.4
)
+
scale_fill_brewer(palette
=
"Blues"
, breaks
=
rev(levels(uspopage$AgeGroup)))
Figure 4-21. Reversed legend order, lines, and a different palette