r - 在 ggthemes 中为scale_colour_colorblind()选择颜色

标签 r ggplot2 color-blindness 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

关于r - 在 ggthemes 中为scale_colour_colorblind()选择颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60301305/

相关文章:

r - 为什么词干提取对于情感分析很重要

r - 在多个工作表中将数据框列表写入 Excel

r - 直方图中不同的 bin 宽度与 ggplot2,r

python - 根据 R 或 python 中的条件将一个列列表中的值替换为另一列列表中的值

r - ggplot2 grid.export 绘图大小 SVG

r - 带有值的热图(ggplot2)——如何使单元格成为正方形并自动调整大小?

colors - 色盲网页设计师有任何资源吗?

r - 带有 R : Can't change the projection for points/coordinates 的 map

java - 为色盲人士增强图像

r - 如何生成对色盲友好的 30 种不同颜色?