如何在堆积的条形图中重新排列条形?

时间:2018-07-03 19:17:40

标签: r ggplot2

我正在尝试更改堆积条形图中的条形顺序,但运气不佳。我想在底部显示致命伤,在顶部显示伤害。有没有办法做到这一点?

图表代码:

ggplot(GroupedHealth) + 
    aes(x=reorder(EVTYPE, Total), , y=Total, fill=Type) +
    geom_histogram(stat="identity", alpha=1)+
    ggtitle("Total fatalities & injuries by weather events in U.S.") + 
    theme(plot.title = element_text(lineheight=0.8, face="bold")) +
    xlab("Event type") +      
    coord_flip()

enter image description here

我尝试过:

更改Type var的级别。

GroupedHealth$Type<- ordered(GroupedHealth$Type, levels = c("Fatalities", "Injuries"))

播放数据框的排序。

 GroupedHealth <-   GroupedHealth[order(GroupedHealth$Type,decreasing=F),]

注意:要上传的数据很大。

0 个答案:

没有答案
相关问题