Are there any good packages for colour palettes in R that can handle many data classes? I have 16 sequential data classes. I tried RColorBrewer but it has a max of 9 data cl
For colorblind viewers, take a look at the Safe
palette from the rcartocolor package. This palette consists of 12 easily distinguishable colors.
# install.packages("rcartocolor")
# or
# install.packages("remotes")
# remotes::install_github("Nowosad/rcartocolor")
library(rcartocolor)
nColor <- 12
scales::show_col(carto_pal(nColor, "Safe"))
Another popular colorblind friendly palette is the Okabe Ito scale
Example:
library(ggplot2)
library(rcartocolor)
library(patchwork)
theme_set(theme_classic(base_size = 14) + theme(panel.background = element_rect(fill = "#f6f1eb")))
set.seed(123)
df <- data.frame(x = rep(1:5, 8),
value = sample(1:100, 40),
variable = rep(paste0("category", 1:8), each = 5))
safe_pal <- carto_pal(12, "Safe")
# https://github.com/clauswilke/colorblindr/blob/master/R/palettes.R
palette_OkabeIto <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7", "#999999")
palette_OkabeIto_black <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442",
"#0072B2", "#D55E00", "#CC79A7", "#000000")
# plot
p1 <- ggplot(data = df, aes(x = x, y = value)) +
geom_line(aes(colour = variable), size = 1) +
scale_color_manual(values = palette_OkabeIto_black)
p2 <- ggplot(data = df, aes(x = x, y = value)) +
geom_col(aes(fill = variable)) +
scale_fill_manual(values = safe_pal)
p1 / p2