Colors
This (as yet) much too short entry just points out that of course R, even though normally producing black on white graphs, offers a wide variety of colours. Regrettably, the many features that are available mean that the issue, again, is rather complex.
Introduction
The colours that come with R unsurpringly are referred to by the col
parameter in command plot()
. For instance, the command plot(y,x, col="green")
will produce a scatterplot of y vs. x (provided that vectors with these names are available), with the data values in green (whereas the remainder of the graph will be black).
Graphs created with the ggplot2
package use keyword color
("colour" is also accepted, I've learned). The lattice
package, which seems to have become a little less en vogue, uses col
.
Colours are often used to distinguish elements in a graph. For instance, in a box-and-whisker plot that compares four groups you may wish to give each group a different colour. To achieve this (in a plot()
environment), colours must be given as a vector as in col=c("deepskyblue", "green", "chartreuse3", "darkolivegreen1")
.
How can we know which colours are available? For the time being, please use this sheet by Earl F. Glynn that gives a good overview of many of the available colors. You may also use demo("colors")
from the R prompt.
Beyond the basics
Other colour schemes (or colour palettes) are available, see, e.g., library RColorBrewer
.
© W. Ludwig-Mayerhofer, R Guide | Last update: 23 Jun 2025