请参阅ggplot 2中现有调色板中的特定颜色名称

时间:2016-06-03 21:15:03

标签: r ggplot2 colors

我希望看到docid调色板中的颜色名称。我需要在我的图表中使用数字4和5,即紫色和橙色。我不知道他们的代码。请指出我在哪里可以找到他们的名字或代码。非常感谢。

我提到的set1就在这里:

https://learnr.wordpress.com/2009/04/15/ggplot2-qualitative-colour-palettes/

非常感谢任何建议

1 个答案:

答案 0 :(得分:11)

您可以按ggplot_build找到代码。

# fake data
df <- data.frame(x=1:8, y=1, col=letters[1:8])

# Construct the plot
g <- ggplot(df, aes(x=x, y=y, color=col)) + geom_point(size=5) +
  scale_color_brewer(palette="Set1")

g

custom routing

# Retrieve the color
colors <- ggplot_build(g)$data[[1]]$colour

# Double check
plot(df$x, df$y, col=colors, pch=20, cex=5)

enter image description here

# color 4 and 5
colors[4:5]
[1] "#984EA3" "#FF7F00"