onecolor with R
There are 5 main methods to call a color in R. Click the buttons below to see a description of them
Name → The most common method is to call a color by its name. R offers about 657 color names. You can read all of them using
rgb() → The
rgb() function allows to build a color using a quantity of red, green and blue. An additionnal parameter is available to set the transparency. All parameters ranged from 0 to 1.
Number → Also possible to call a function by its number. For instance, if you need the color number 143, use `colors()`.
RColorBrewer is the most famous package when it comes to build color palette with R. It provides quality continuous, sequential and categorical color palette. Examples below should get you started with this package, and give you an overview of all the available color palettes.
paletteer package gives access to all the existing color palettes in
library(paletteer) ; paletteer_c(package = "scico", palette = "berlin", n = 10)
Once you've found a color palette you like, you probably need to map it to a categorical or a numeric variable. This pretty easy to do with ggplot2, but much harder in base R. Basically, you have to transform the variable of interest in an integer that will be used to call the appropriate color.
Two histograms on same Axis
Compare the distribution of 2 variables with this double histogram built with base R function.
Histogram with colored tails
Coloring tails sometimes allow to highlight specific areas of the distribution.