我正在使用ggplot2创建相当多的facet_wrapped geom_line图。
虽然每个图最多只有八条线,但当综合在一起时,图例上显示的类别更像是20个类别。
与这个类似:Recommend a scale colour for 13 or more categories和这个:In R,how do I change the color value of just one value in ggplot2's scale_fill_brewer?我想人为地增加我可以使用colorbrewer的高对比度颜色集显示的颜色的数量。
一种显而易见的方法似乎是“循环”调色板中的颜色,每次都使用不同的线条符号。因此,带有‘x’的亮红色与带有‘o’的亮红色可能是不同的类别。
有人能想到我该怎么做吗?
谢谢!
编辑
这里有一些(清理过的)数据,以及我用来生成我的图的R代码。
数据:http://orca.casa.ucl.ac.uk/~rob/Stack%20Overflow%20question/stack%20overflow%20colours%20question%20data.csv
R代码:
csvData <- read.csv("stack overflow colours question data.csv")
p <- ggplot(csvData,
aes(year, percentage_of_output, colour=category, group=category))
p +
geom_line(size=1.2) +
labs(title = "Can I recycle the palette colours?", y = "% of output") +
scale_colour_brewer(palette = "Set1") +
theme(plot.title = element_text(size = rel(1.5))) +
facet_wrap("country_iso3", scales="free_y")发布于 2013-02-27 21:27:09
制作包含20个级别的数据帧(如字母)。
df<-data.frame(group=rep(c(LETTERS[1:20]),each=5),x=rep(1:5,times=20),y=1:100)您可以使用scale_colour_manual()来设置线条的颜色-在示例中,我使用了5个SET1,并重复使用了4个times (总数为20)。然后设置形状,添加geom_point()和scale_shape_manual()以及五种不同的形状,并对它们重复each四次(总数也是20次)。
library(RColorBrewer)
ggplot(df,aes(x,y,colour=group))+geom_line()+geom_point(aes(shape=group),size=5)+
scale_colour_manual(values=rep(brewer.pal(5,"Set1"),times=4))+
scale_shape_manual(values=rep(c(15,16,17,18,19),each=5))

https://stackoverflow.com/questions/15112440
复制相似问题