colours
Author

Thomas Manke

Colours

Colours can be referenced in different ways:

Code
plot(iris$Petal.Length, col = "red")      # by name: try colours()

Code
plot(iris$Petal.Length, col = rgb(0,0,1)) # by RGB-value: ?rgb

Code
plot(iris$Petal.Length, col = 3)          # by index into color palette: ?palette()

Palettes

Palettes can be used to refer to colour by index.

Code
mycol=c("black", "skyblue", "maroon2")     # define your own set of colours; Warning: don't overdo 
palette(mycol) 
plot(iris$Petal.Length, col=iris$Species)

Code
palette("default")                         # not the best?
plot(iris$Petal.Length, col=iris$Species)

Code
palette("Set 1")                           # check palette.pals() for more choices
plot(iris$Petal.Length, col=iris$Species)

… and there is more

Lots of studies have been made on the choice of appropriate colour schemes: https://colorbrewer2.org

There are additional packages to simplify the choice of palette

Code
library(RColorBrewer)
my_col=brewer.pal(4, "Dark2")
palette(my_col)
plot(iris$Petal.Length, col=iris$Species)