R Color Cheat Sheet



256 colors - cheat sheet Errata Exists: There seem to be duplicate color names in the list, and there are clashes between web and X11 colors in the CSS color scheme, as described here. There are 2 margin areas in base R plots: margin and oma.You can control their size calling the par function before your plot and giving the corresponding arguments. Mar for margin. Oma for outer margin area. For both arguments, you must give four values giving the desired space in the bottom, left, top and right part of the chart respectively. Fill color col = horizontal horiz = TRUE. R Base Graphics Cheatsheet Joyce&Robbins,&joycerobbins1@gmail.com& Created Date: 3/7/2016 5:52:42 PM. This article presents the top R color palettes for changing the default color of a graph generated using either the ggplot2 package or the R base plot functions. You’ll learn how to use the top 6 predefined color palettes in R, available in different R packages: Viridis color scales viridis package.Colorbrewer palettes RColorBrewer packageGrey color palettes ggplot2 package. R Markdown is an authoring format that makes it easy to write reusable reports with R. You combine your R code with narration written in markdown (an easy-to-write plain text format) and then export the results as an html, pdf, or Word file. You can even use R Markdown to build interactive documents and slideshows. Updated February 16.

R Color Basics

R graphical devices support a broad range of colors and color functions. The colors() command with no input arguments returns a list of all available colors in R. Presently, there are 657 colors. In practice, declaring colors can be achieved three ways:

  • character names (e.g. “red”, “orange”, “yellow”),
  • 3-digit RGB values (e.g. 255 0 0; 265 155 0; 255 255 0), and
  • hexadecimal strings (e.g. “#FF0000”, “#FFA500”, “#FFFF00”).

R Color character names

Index extraction from the colors() list is one way to reveal available colors. For example:

2
4
6
8
10
barplot(1,axes=FALSE,col='steelblue')
# Display all green colors
axes=FALSE,
xlim=c(0,5),
col=colors()[grep('green',colors())])

RGB Color Codes in R

The function col2rgb() can be used to extract the RGB (red-green-blue) components of a color.

R Color Ramps and Hex Triplets

Hex triplets can be used in R in place of color names and are convenient when functions define color selection. For example, it is impossible to use character names to precisely define a color ramp, or the the range of colors that interpolate between a start and end color. Its easy with hex triplets!