captcoma
captcoma

Reputation: 1898

chose colors for scale_colour_colorblind() in ggthemes

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)

Upvotes: 2

Views: 1683

Answers (2)

dario
dario

Reputation: 6483

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

Upvotes: 3

StupidWolf
StupidWolf

Reputation: 46968

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

Upvotes: 2

Related Questions