繁体   English   中英

在 ggthemes 中为 scale_colour_colorblind() 选择颜色

[英]chose colors for scale_colour_colorblind() in ggthemes

我想从ggthemes选择ggthemes colorblind_pal()特定颜色

这有效:

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()

现在我想为我的情节选择colorblind_pal()特定颜色。 我该如何选择它们?

我尝试了以下但没有成功:

my_palette <- palette(c("#000000","#F0E442","#D55E00"))
p + theme_igray() + scale_colour_colorblind(my_palette)

您可以使用scale_color_manual来手动指定要使用的颜色:

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

因为你已经有了颜色,你可以只使用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))

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM