推荐13个或更多类别的比例颜色 [英] Recommend a scale colour for 13 or more categories
问题描述
ggplot2的默认比例为13种或更多颜色不提供高度的视觉差异。
此外,最长的啤酒杯终止于12个类别(Set3)。
The default scale for ggplot2 for 13 or more colours does not provide a high degree of visual differentiation. In addition, the longest of the brewer scales ends at 12 categories (Set3).
您可以推荐一个对13个或更多类别有用的颜色标尺吗?
Can you recommend a colour scale that would be visually useful for 13 or more categories?
可重现的范例:
dat <- data.frame(value=rnorm(100),
category=sample(letters[1:13],100,replace=T),
other=sample(letters[1:5],100,replace=T))
# Default Scale
ggplot(dat, aes(other,value,color=category)) +
geom_point(size=6) +
coord_flip()
# Brewer Scale // notice the blank at the end!
ggplot(dat, aes(other,value,color=category)) +
geom_point(size=6) +
coord_flip() +
scale_color_brewer(palette="Set3")
注意:facet在我的情况下不是一个选项(客户不喜欢, )
Note: facetting is not an option in my case (client doesn't like it, go figure)
推荐答案
您可以使用 colorRampPalette
和
You could use colorRampPalette
and scale_colour_manual
to fudge a 13th category.
set3 <- colorRampPalette(brewer.pal('Set3',n=12))
ggplot(dat, aes(other,value,color=category)) +
geom_point(size=6) +
coord_flip() +
scale_color_manual(values = setNames(set3(13), levels(dat$category)))
这将分解,如果你设置所需的数字太高,颜色将不会很好地区分。
This will break down, in that the colours will not be nicely distinguishable if you set the required numbers too high.
这篇关于推荐13个或更多类别的比例颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!