[My Gallery of Graphs] Mastering the art of building classic and stylish graphics in R: Color Palettes in R. This document constains some examples of color palettes that can be used in R graphs.
1. Color Palettes in R
Author: Michel Alves dos Santos
[[www.michelalves.com :: http://www.lcg.ufrj.br/Members/malves/ ]]
2.
3. #------------------------------------------------------------------------------#
# Color Palettes.
# Date : 20 February, 2012
# Author : Michel Alves dos Santos
#------------------------------------------------------------------------------#
#------------------------------------------------------------------------------#
# Loading required libraries
#------------------------------------------------------------------------------#
require(RColorBrewer)
#------------------------------------------------------------------------------#
# Color Settings
#------------------------------------------------------------------------------#
my.palette.nc <- 255 # number of colors
my.palette.rc <- 1:205 # range of colors
#-------------------------------------------------------------------------------
# Color Palettes - Definition of names and component colors
#-------------------------------------------------------------------------------
# Matlab falshy jet color
jet.colors.palette <- c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000")
# Pastel palette
my.pastel.palette <- rev(c("#62739F", "#8DABBD", "#AB9EB0", "#FFF0A7", "#F4BAA4"))
# Sequential RColorBrewer: for more information type display.brewer.all() or display.brewer.all(type="seq")
# The sequential palettes names are: Blues BuGn BuPu GnBu Greens Greys Oranges OrRd PuBu PuBuGn PuRd
# Purples RdPu Reds YlGn YlGnBu YlOrBr YlOrRd. All the sequential palettes are available in variations from 3
# different values up to 9 different values.
YlGnBuPalette <- brewer.pal(9, "YlGnBu")
YlOrBrPalette <- brewer.pal(9, "YlOrBr")
YlOrRdPalette <- brewer.pal(9, "YlOrRd")
# Divergent RColorBrewer: type display.brewer.all(type="div"). The diverging palettes are: BrBG PiYG PRGn
# PuOr RdBu RdGy RdYlBu RdYlGn Spectral. All the diverging palettes are available in variations from 3
# different values up to 11 different values.
SpectralPalette <- brewer.pal(11, "Spectral")
RdYlGnPalette <- brewer.pal(11, "RdYlGn")
RdYlBuPalette <- brewer.pal(11, "RdYlBu")
# Qualitative RColorBrewer: type display.brewer.all(type="qual"). For qualitative palettes, the lowest
# number of distinct values available always is 3, but the largest number is different for different palettes.
# It is given together with the palette names in the following table: Accent 8 Dark2 8 Paired 12 Pastel1 9
# Pastel2 8 Set1 9 Set2 8 Set3 12
Pastel1Palette <- brewer.pal(9, "Pastel1")
Pastel2Palette <- brewer.pal(8, "Pastel2")
#------------------------------------------------------------------------------#
# Deifinition of Palettes with number of color equal to: my.palette.nc
#------------------------------------------------------------------------------#
# Palette using rainbow palette
RainbowPalette <- colorRampPalette(rev(rainbow(300)[my.palette.rc]))(my.palette.nc)
RainbowPaletteV2 <- colorRampPalette((rainbow(300)[my.palette.rc]))(my.palette.nc)
RainbowPaletteV3 <- colorRampPalette(rev(rainbow(600)[my.palette.rc]))(my.palette.nc)
RainbowPaletteV4 <- colorRampPalette((rainbow(600)[my.palette.rc]))(my.palette.nc)
RainbowPaletteV5 <- colorRampPalette(rev(rainbow(800)[my.palette.rc]))(my.palette.nc)
RainbowPaletteV6 <- colorRampPalette((rainbow(800)[my.palette.rc]))(my.palette.nc)
# Red Blue Palette
RedBluePalette <- colorRampPalette(c("red", "white", "blue"))(my.palette.nc)
# Red Blue Palette with lab space
RedBlueLabPalette <- colorRampPalette(c("red", "white", "blue"), space = "Lab")(my.palette.nc)
# Blue Orange palette
BlueOrangePalette <- colorRampPalette(c("blue", "cyan", "green", "yellow", "orange", "red"))(my.palette.nc)
# Heat Color palette
HeatPalette <- rev( heat.colors(my.palette.nc, alpha = .75) )
# Terrain Color Palette
TerrainPalette <- rev( terrain.colors(2*my.palette.nc, alpha = .75) )
# Rainbow Green to Red Palette
GreenToRedPalette <- rev( rainbow(5*my.palette.nc, alpha = .55)[0: 400] )
# Rainbow Green to Red Palette version 2
GreenToRedPaletteV2 <- c( rainbow(my.palette.nc, start = 0, end = 0.4) )
# Topo Color Palette
TopoPalette <- rev( topo.colors(10*my.palette.nc, alpha = .50)[0:840] )
# Cm Color Palette
CmPalette <- cm.colors(5*my.palette.nc, alpha = 1)
# Matlab jetcolor palette
JetColorPalette <- colorRampPalette(jet.colors.palette)(my.palette.nc)
105. The End.
Michel Alves dos Santos
Color Palettes in R
The surface used for display of the examples
is the representation of high-pass Gaussian
filter in the frequency domain.