Graphics Reference
In-Depth Information
RGB colors are specified as six-digit hexadecimal (base-16) numbers of the form "#RRGGBB" .
In hexadecimal, the digits go from 0 to 9, and then continue with A (10 in base 10) to F (15 in
base 10). Each color is represented by two digits and can range from 00 to FF (255 in base 10).
So, for example, the color "#FF0099" has a value of 255 for red, 0 for green, and 153 for blue,
resulting in a shade of magenta. The hexadecimal numbers for each color channel often repeat
the same digit because it makes them a little easier to read, and because the precise value of the
second digit has a relatively insignificant effect on appearance.
Here are some rules of thumb for specifying and adjusting RGB colors:
▪ In general, higher numbers are brighter and lower numbers are darker.
▪ To get a shade of grey, set all the channels to the same value.
▪ The opposites of RGB are CMY: Cyan, Magenta, and Yellow. Higher values for the red
channel make it more red, and lower values make it more cyan. The same is true for the pairs
green and magenta, and blue and yellow.
See Also
A chart of RGB color codes .
Using a Colorblind-Friendly Palette
Problem
You want to use colors that can be distinguished by colorblind viewers.
Solution
Use the palette defined here ( cb_palette ) with scale_fill_manual() ( Figure 12-10 ):
library(gcookbook) # For the data set
# Base plot
p <- ggplot(uspopage, aes(x = Year, y = Thousands, fill = AgeGroup)) + geom_area()
# The palette with grey:
cb_palette <- c( "#999999" , "#E69F00" , "#56B4E9" , "#009E73" , "#F0E442" ,
"#0072B2" , "#D55E00" , "#CC79A7" )
# Add it to the plot
p + scale_fill_manual(values = cb_palette)
Search WWH ::




Custom Search