更改R中的堆积条形图顺序

时间:2020-05-09 13:26:15

标签: r ggplot2

我目前正在绘制堆叠的条形图,并希望更改不同部分的显示顺序。这是我的图形当前的样子:

enter image description here

当前代码:

#top 10 countries with the most medals between 1924-2000, all seasons, broken down by medal type
maingraph2 <- cleaneddataset %>% 
  group_by(NOC,Medal) %>% 
  summarise(MedalCount = sum(MedalCount))

maingraph2 <-maingraph2[order(-maingraph2$MedalCount),]
maingraph2graphdata <- subset(maingraph2, NOC == 'USA'| NOC == 'URS'| NOC == 'SWE'| NOC == 'ITA'| NOC == 'HUN'| NOC == 'GER'
                             | NOC == 'GDR'| NOC == 'GBR'| NOC == 'FRA'| NOC == 'AUS')



ggplot(sorted, aes(x = NOC, y = MedalCount))+
  geom_col(aes(fill = (Medal)), width = 0.7)

图表数据摘要: enter image description here

我希望条形图从上到下的顺序为金(绿色),银(蓝色)和青铜(红色)。我在网上找到了其他建议来更改列顺序,但是这只是颠倒了顺序,使Gold仍然处于中间位置。

谢谢您的时间!

0 个答案:

没有答案
相关问题