1

I would like to chose specific colors of the colorblind_pal() from ggthemes

This works:

library(ggplot2)
library(ggthemes)

p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg,
                                     colour = factor(gear))) + facet_wrap(~am)
p + theme_igray() + scale_colour_colorblind()

Now I would like to chose specific colors of the colorblind_pal() for my plot. How can I chose them?

I tried following with no success:

my_palette <- palette(c("#000000","#F0E442","#D55E00"))
p + theme_igray() + scale_colour_colorblind(my_palette)
captcoma
  • 1,768
  • 13
  • 29

2 Answers2

3

You could use scale_color_manual in order to manually specify the colors to use:

library(ggplot2)
library(ggthemes)

p <- ggplot(mtcars) +
  geom_point(aes(x = wt, y = mpg, colour = factor(gear))) +
  facet_wrap(~am) +
  theme_igray() +
  scale_color_manual(values = c("#000000","#F0E442","#D55E00"))
p
dario
  • 6,415
  • 2
  • 12
  • 26
2

Since you already have the colors, you can just use scale_color_manual:

library(ggthemes)
library(ggplot2)
COLS=colorblind_pal()(8)

COLS = COLS[c(1,5,7)]

p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg,
                                     colour = factor(gear))) + facet_wrap(~am)
p + theme_igray() + scale_colour_manual(values=COLS))

enter image description here

StupidWolf
  • 45,075
  • 17
  • 40
  • 72