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. 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).

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, colours must be given as a vector as in col=c("deepskyblue", "green", "chartreuse3", "darkolivegreen1").

How can we know which colours are available? For time being, please use this page by Earl F. Glynn that gives a good overview of many of the available colors plus interesting links about color in science and related stuff. 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: 03 Apr 2017