How does colour contrasting in R work? I'd assume there is some trigger in the colour hex values that can be used to help tell whether one should change colour for a label to something lighter/darker. I'm interested in a general solution - I know there are packages that do go colour contrast controls for ggplot2
. I'd more like an approach that I can control the degree of colour contrasts.
This code illustrates the point. The scales
package handles colour contrast great. I would just like to have some more control over it.
library(tidyverse)
library(scales)
show_col(c("darkred",
"wheat",
"darkblue",
"steelblue"))
tibble(key = letters[1:4],
value = 1:4) %>%
ggplot(aes(key, value))+
geom_col(aes(fill = key))+
geom_text(aes(label = key),
position = position_stack(vjust = 0.5))+
scale_fill_manual(values = c("darkred",
"wheat",
"darkblue",
"steelblue"))