ggplot2的默认缩放比例(用于13种或更多颜色)不能提供高度的视觉区分。
此外,最长的啤酒天平以12个类别(Set3)结尾。
您能推荐一种对13个或更多类别视觉上有用的色标吗?
可重现的示例:
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")
注意:在我的情况下,不能选择faceting(客户不喜欢,请看图)
最佳答案
您可以使用colorRampPalette
和scale_colour_manual
来捏造第13个类别。
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)))
如果您将所需的数字设置得太高,则颜色将无法很好地区分,这将被分解。
关于推荐13种或以上类别的比例尺颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13616515/