Tag: Rcolors

In the R post, we will present how to create your own color palettes and how to work with other palettes such as RColorBrewer, wesanderson and hex codes from http://www.colorcombos.com for exciting color palettes.

Advertisements

There are several color palettes available in R such as rainbow(), heat.colors(), terrain.colors(), and topo.colors(). We can visualize these as 3D pie charts using the plotrix R package.

Other popular color palettes include the RColorBrewer package that has a variety of sequential, divergent and qualitative palettes and the wesandersonpackage that has color palettes derived from his films.

# To get an idea of the colors available
head(colors())
length(colors()) # 657
# To see all 657 colors as a color chart you can source the R script to generate a pdf version in your working directory

# We can create choose a palette based on the R chart as follow:
mycols <- colors()[c(8, 5, 30, 53, 118, 72)] #
# or you could enter the color names directly
# mycols <- c("aquamarine", "antiquewhite2", "blue4", "chocolate1", "deeppink2", "cyan4")
# You could also get and store all distinct colors in the cl object and use the sample function to select colors at random
cl <- colors(distinct = TRUE)
set.seed(15887) # to set random generator seed
mycols2 <- sample(cl, 7)

You can also create color palettes with hex color codes. A great example of this is to work with popular color palettes available on the http://www.colorcombos.com website. This website has various palettes you can choose from and even derive color palettes from your favorite websites. For example, let’s grab the color palette from the rjbioinformatics.com website at http://www.colorcombos.com/grabcolors.html .

After entering the URL of our website, we will receive the hex codes for the color scheme used on the website.

We can even export the colors as little pencils 🙂

You can also choose from hundred of color schemes based on your color of choice. For example, we will also create a color palette based on the color olive – ColorCombo382.

We can also create a color palette with the colorRampPalette() to use for heatmaps and other plots. For this example, we will use the leukemia dataset available in the GSVAdata package, which corresponds to microarray data from 37 human acute leukemias where 20 of these cases are Acute lymphoblastic leukemia (ALL) and the other 17 are ALL’s with Mixed leukemia gene rearrangements. For more information on the study please see Armstrong et al. Nat Genet 30:41-47, 2002.