Graphics Reference
In-Depth Information
Table 12-1. Discrete fill and color scales
Fill scale
Color scale
Description
scale_fill_discrete() scale_colour_discrete()
Colors evenly spaced around the color wheel (same as hue)
Colors evenly spaced around the color wheel (same as dis-
crete)
scale_fill_hue()
scale_colour_hue()
Greyscale palette
scale_fill_grey()
scale_colour_grey()
ColorBrewer palettes
scale_fill_brewer()
scale_colour_brewer()
Manually specified colors
scale_fill_manual()
scale_colour_manual()
In the example here we'll use the default palette (hue), and a ColorBrewer palette (
Figure 12-4
):
library(gcookbook)
# For the data set
# Base plot
p
<-
ggplot(uspopage, aes(x
=
Year, y
=
Thousands, fill
=
AgeGroup))
+
geom_area()
# These three have the same effect
p
p
+
scale_fill_discrete()
p
+
scale_fill_hue()
# ColorBrewer palette
p
+
scale_fill_brewer()
Figure 12-4. Left: default palette (using hue); right: a ColorBrewer palette