The goal of brewerland is: to make your life colourful
The following data are made availabe:
discrete_colours
: A character vector of 297 discrete RColorBrewer colours.The following functions are implemented:
colourScale
: Colour Vectors of any length for any data type colourPal
: Flexile RColorBrewer PalettesareColours
: Test if character strings are valid coloursbrewerPalNames
: RColorBrewr Palette NamesisBrewerPal
: Test if a name is a valid RColorBrewer Palette nameisBrewerDiv
: Test if a name is a divergent RColorBrewer Palette brewerPalLength
: Maximum length of an RColorBrewer PalettebrewerPalInfo
: Retrieve information on RColorBrewer PalettesNote: brewerland's two most useful functions are colourPal() and colourScale(). See ?colourPal and ?colourScale for more information.
You can install the released version of brewerland from GitHub with:
# install.packages("devtools")
devtools::install_github("jlaffy/brewerland")
Some basic examples which show you how to solve some common problems:
library(brewerland)
# discrete_colours is a brewerland character vector with 297 brewer colours
scales::show_col(discrete_colours, labels = F)
### Choose a palette by type ###
# default palette for continuous data is 'YlOrBr'
scales::show_col(colourPal(name = NULL, type = 'seq'), labels = FALSE)
# default palette for divergent data is 'RdBu' (reversed)
scales::show_col(colourPal(name = NULL, type = 'div'), labels = FALSE)
# default palette for qualitative/categorical data is 'Dark2'
scales::show_col(colourPal(name = NULL, type = 'qual'), labels = FALSE)
### Choose a palette by RColorBrewer palette names ###
scales::show_col(colourPal(name = 'Spectral'), labels = FALSE)
scales::show_col(colourPal(name = 'Spectral', reverse = T), labels = FALSE)
scales::show_col(colourPal(name = 'Spectral', reverse = T, shuffle = T), labels = FALSE)
### An Example with continuous (sequential) data ###
set.seed(1492)
toy_numeric_data = sort(rnorm(1:100))
# default colours for sequential data
scales::show_col(colourScale(data = toy_numeric_data), labels = FALSE)
# different RColorBrewer Palette
scales::show_col(colourScale(data = toy_numeric_data, pal = 'RdPu'), labels = F)
# data split into 4 equally-spaced groups
scales::show_col(colourScale(data = toy_numeric_data, pal = 'RdPu', bin = T, n = 4), labels = F) # data binned into 4 groups
# data split into 4 equally-sized groups
scales::show_col(colourScale(data = toy_numeric_data, pal = 'RdPu', quantile = T, n = 4), labels = F) # data binned into 4 groups
# neutral colour for NA values. If you want a neutral colour for a subset of points, set these equal to 'NA'.
toy_numeric_data[toy_numeric_data >= -0.5 & toy_numeric_data <= 0.5] <- NA
scales::show_col(colourScale(data = toy_numeric_data, na.colour = "#808080"), labels = F)
# semi transparent colours
scales::show_col(colourScale(data = toy_numeric_data, alpha = 0.5), labels = F)
### An Example with qualitative data ###
toy_categorical_data = sort(rep(letters[1:5], 10))
scales::show_col(colourScale(data = toy_categorical_data), labels = FALSE)
# choose levels
scales::show_col(colourScale(data = toy_categorical_data, levels = letters[5:1]), labels = FALSE)
# provide a different colour palette
scales::show_col(colourScale(data = toy_categorical_data, levels = letters[5:1], pal = discrete_colours))
# return colour key for qualitative colours
colourScale(data = toy_categorical_data, levels = letters[5:1], pal = discrete_colours, return.legend = T)$legend
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.