colorblind-friendly palette in r

# Step 1: Install and load the RColorBrewer package
install.packages("RColorBrewer")
library(RColorBrewer)

# Step 2: Choose a colorblind-friendly palette from RColorBrewer
# Use colorblind-friendly palettes from the ColorBrewer website: https://colorbrewer2.org/
# For example, we'll use the "Set2" palette with 8 colors
palette_name <- "Set2"
num_colors <- 8
color_palette <- brewer.pal(n = num_colors, name = palette_name)

# Step 3: Display the chosen colorblind-friendly palette
display.brewer.all(type = "div", color_palette)

# Step 4: Use the selected palette in your plots
# For example, in ggplot2
library(ggplot2)
ggplot(data = your_data, aes(x = x_variable, y = y_variable, fill = factor(group_variable))) +
  geom_bar(stat = "identity") +
  scale_fill_manual(values = color_palette)