如何更改条形图内的颜色?
因此,我使用以下代码来获取条形图:
selected_players %>%
group_by(Player, Season) %>%
summarise(total= sum(Goals)) %>%
ggplot(aes(x= Player, y= total, fill= Season)) +
geom_bar(stat= "identity")+
scale_color_manual(values= pointcolor)
pointcolor<- c("14-15"= "green",
+ "15-16"= "wheat4",
+ "16-17"= "bisque",
+ "17-18"= "chartreuse",
+ "18-19"= "violetred1",
+ "19-20"= "grey15",
+ "20-21"= "steelblue1")
并且我得到了下图中的图表。我的问题是:如何在此图表上指定每个季节所需的颜色? 感谢您抽出时间。
So, I have used the following code to obtain a bar graph:
selected_players %>%
group_by(Player, Season) %>%
summarise(total= sum(Goals)) %>%
ggplot(aes(x= Player, y= total, fill= Season)) +
geom_bar(stat= "identity")+
scale_color_manual(values= pointcolor)
pointcolor<- c("14-15"= "green",
+ "15-16"= "wheat4",
+ "16-17"= "bisque",
+ "17-18"= "chartreuse",
+ "18-19"= "violetred1",
+ "19-20"= "grey15",
+ "20-21"= "steelblue1")
and I'm getting the graph in the image below. My question is: How can I specify the colors I want for each season on this graph?
Thank you for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 @stefan 建议的那样,使用
scale_fill_manual ()
而不是scale_color_manual ()
,因为您尚未将任何变量映射到美学中的颜色。示例代码:
使用
scale_fill_manual()
绘图使用
scale_color_manual()
绘图示例数据:
As suggested by @stefan use
scale_fill_manual ()
instead ofscale_color_manual ()
because you have not mapped any variable to colour in the aesthetic.Sample code:
Plot with
scale_fill_manual()
Plot with
scale_color_manual()
Sample data: