我知道如何通过在scale_color_discrete中使用中断来改变我的传奇的顺序。我还知道如何使用scale_color_brewer更改调色板。
然而,我不知道如何以适当的方式将这些组合在一起。如果我使用下面的代码,R将指定我想要的调色板,然后重新排序我的列表。我希望这种情况发生在相反的顺序上,因为我希望根据我指定的顺序进行顺序调色板着色。我怎样才能做到这一点,而不必手动输入颜色代码?
library(ggplot2)
df <- data.frame(team=c("liquid","faze","faze","wtsg","liquid","wtsg","faze","liquid","faze","wtsg"),elo=c(1550,1530,1511,1541,1499,1522,1480,1470,1510,1440),date=c("2020-03-08","2020-03-08","2020-03-01","2020-03-08","2020-02-24","2020-02-24","2020-02-24","2020-02-16","2020-02-16","2020-02-16"))
df$team <- as.character(df$team)
df$date <- as.Date(df$date)
order=c("liquid","wtsg","faze")
# This will give me the palette I desire and the order I desire, however, the color progression of the palette will not be in the same order as the legend, which is what I want.
ggplot(data=df)+
geom_line(mapping=aes(x=date,y=elo,color=team),size=2)+
scale_color_discrete(palette="Spectral", breaks=order)发布于 2020-03-09 04:48:10
响应您的编辑,而不是尝试同时设置自定义级别和自定义调色板,在绘图之前设置组级别会更容易。
df$team <- factor(df$team, levels = order)
ggplot(data = df) +
geom_line(mapping = aes(x = date, y = elo, color = team), size = 2) +
scale_color_brewer(palette = "Spectral")

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