Hue, Chroma, Luminance Color Space

The hcl() function generates HEX codes and can be used to create color palettes.

library(tidyverse)

# CAN USE BASE
#install.packages("hcl")
#library(hcl)

Default colors:

df<-data.frame(x=1:5)

ggplot(df, aes(x, y=1, fill=x))+
  geom_tile()+
  coord_equal()+
  theme_void()+
  guides(fill="none")

Hue

The hue of the color specified as an angle in the range [0,360]. 0 yields red, 120 yields green 240 yields blue, etc.

Fix chroma and luminance, changing only hue.

thisH<-hcl(h = c((1:5)*72), c = 200, l = 50)

ggplot(df, aes(x, y=1, fill=as.factor(x)))+
  geom_tile()+
  scale_fill_manual(values=thisH)+
  coord_equal()+
  theme_void()+
  guides(fill="none")

Chroma

The chroma of the color. The upper bound for chroma depends on hue and luminance.

thisC<-hcl(h = 280, c = c((1:10)*50), l = 70)

ggplot(df, aes(x, y=1, fill=as.factor(x)))+
  geom_tile()+
  scale_fill_manual(values=thisC)+
  coord_equal()+
  theme_void()+
  guides(fill="none")

Luminance

A value in the range [0,100] giving the luminance of the colour. For a given combination of hue and chroma, only a subset of this range is possible.

thisL<-hcl(h = 280, c = 100, l =  c((0:4)*25))

ggplot(df, aes(x, y=1, fill=as.factor(x)))+
  geom_tile()+
  scale_fill_manual(values=thisL)+
  coord_equal()+
  theme_void()+
  guides(fill="none")