r - 如何使用线条符号回收 colorbrewer 调色板中的颜色

标签 r ggplot2 colorbrewer

我正在使用 ggplot2 创建相当多的 facet_wrap ped geom_line阴谋。

虽然每个情节最多只有 8 行,但将它们放在一起时,图例上可以显示大约 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

代码:

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")

最佳答案

制作包含 20 个级别(作为字母)的数据框。

df<-data.frame(group=rep(c(LETTERS[1:20]),each=5),x=rep(1:5,times=20),y=1:100)

您可以使用 scale_colour_manual()为线条设置颜色 - 在示例中我使用了五个 SET1并重复了四次 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))

enter image description here

关于r - 如何使用线条符号回收 colorbrewer 调色板中的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15112440/

相关文章:

r - 将两个图例添加到 image.plot

r - 使用库 'stringi' 时没有名为 'car' 的包

r - 延长 ggplot2 中密度图的尾部

r - 根据窗口大小动态调整 Shiny 图输出的高度和/或宽度

r - 如何使用 RColorBrewer 调色板设置 ggplot 全局颜色主题

map - 创建在配色方案中正确显示分位数类范围值和相关颜色的等值统计图图例?

r - 如何在R中删除字符串类型的变量中的字符

R,时间序列分解中的不完全元素

r - 如何找到不同几何图形和美学的列表

r - 显示 ggplot2 使用的颜色的十六进制代码