8 Choosing Colors

8.1 RColorBrewer

RColorBrewer is a simple-to-use package for selecting colour palettes from Color Brewer. Recall that there are three palette categories: divergent, qualitative and sequential.

> library(RColorBrewer) 
> display.brewer.all(type="qual") 
Qualitative colour palettes in RColorBrewer

Figure 8.1: Qualitative colour palettes in RColorBrewer

> display.brewer.all(type="div")
Divergent colour palettes in RColorBrewer

Figure 8.2: Divergent colour palettes in RColorBrewer

> display.brewer.all(type="seq")
Sequential colour palettes in RColorBrewer

Figure 8.3: Sequential colour palettes in RColorBrewer

If you want to modify your colour palette and are not sure what the hexadecimal code of the colour is, you can use the colour picker in Adobe software programs (e.g. Illustrator, Photoshop and InDesign) to choose the pixel of interest and interpret the hexadecimal code.}Calling display.brewer.all() without any arguments will display all colour palettes at once. display.brewer.pal() also allows you to specify the number of colours and the colour palette as arguments. Once you have chosen an appropriate palette for your purposes, use brewer.pal() to save the hexadecimal colour codes as a vector. To use the colours, simply call your colour vector in the col argument of the plotting function you are using.

> display.brewer.pal(3,"Dark2")
Custom palettes

Figure 8.4: Custom palettes

> colours<-brewer.pal(3,"Dark2")
> colours
[1] "#1B9E77" "#D95F02" "#7570B3"
> plot(c(1.5,2,2.5), c(1.5,2,2.5), col = colours[1:3],
+   xlim = c(1,3), ylim = c(1,3),
+      pch = 16, cex = 10 , xlab = "", ylab = "")
Custom palettes

Figure 8.5: Custom palettes