条形图显示平均值

时间:2018-09-09 09:03:34

标签: r ggplot2

我有一些用于救灾的财务小组数据,并使用以下代码创建了一些条形图,显示每个灾难类别的资金额:

    ggplot(Template.2006.2017, aes(x=Disaster_category, y=Total_US_required)) + 
geom_bar(stat="identity", fill="lightblue") + 
coord_flip()

现在,我想创建一个类似的图,以均值而不是总值的形式忽略所有NA:s。有关如何执行此操作的任何建议?

这是我的数据(压缩后):

    structure(list(Disaster_category = structure(c(1L, 15L, 17L, 
15L, 5L, 8L, 13L, 8L, 2L, 8L, 2L, 3L, 8L, 2L, 8L, 2L, 10L, 5L, 
7L, 8L, 15L, 2L, 8L, 2L, 15L, 15L, 8L, 15L, 2L, 17L, 2L, 7L, 
2L, 8L, 2L, 3L, 2L, 8L, 8L, 2L, 8L, 17L, 2L, 3L, 8L, 8L, 2L, 
8L, 8L, 8L, 2L, 8L, 3L, 2L, 3L, 2L, 8L, 2L, 3L, 8L, 2L, 8L, 2L, 
15L, 5L, 8L, 13L, 8L, 15L, 2L, 8L, 2L, 3L, 2L, 3L, 15L, 8L, 3L, 
2L, 3L, 8L, 2L, 3L, 2L, 8L, 2L, 8L, 15L, 2L, 8L, 8L, 5L, 2L, 
8L, 2L, 3L, 2L, 17L, 2L, 17L, 2L, 4L, 5L, 8L, 8L, 2L, 8L, 15L, 
2L, 15L, 15L, 7L, 2L, 8L, 2L, 15L, 15L, 7L, 8L, 17L, 2L, 15L, 
8L, 2L, 17L, 2L, 3L, 8L, 2L, 5L, 2L, 8L, 2L, 8L, 8L, 15L, 2L, 
8L, 2L, 15L, 8L, 2L, 15L, 8L, 7L, 8L, 15L, 2L, 8L, 8L, 7L, 13L, 
8L, 2L, 8L, 2L, 8L, 8L, 3L, 2L, 13L, 2L, 3L, 8L, 2L, 15L, 15L, 
8L, 15L, 2L, 5L, 3L, 3L, 8L, 3L, 2L, 8L, 8L, 3L, 2L, 8L, 2L, 
15L, 2L, 17L, 2L, 5L, 2L, 8L, 2L, 15L, 2L, 3L, 8L, 8L, 2L, 8L, 
8L, 2L, 3L), .Label = c("", " ", "Disease", "Disease related disaster", 
"Drought", "Drought & storm", "Extreme temperature / fire", "Flood", 
"Flood & drought", "Insect infestation", "Insect infestation & drought", 
"Landslide & flood", "Landslide / mudslide", "Other", "Storm", 
"Storm & flood", "Winter"), class = "factor"), Total_US_received_from.CERF = c(NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 678307.8333, 
678307.8333, 678307.8333, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1110469.5, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, 1905355, NA, NA, NA, NA, NA, NA, NA, NA, NA, 2493246, 
2493246, 2493246, 2493246, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, 333333.3333, 333333.3333, 333333.3333, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 9365420, 
NA, NA, 14321419, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), 
    Total_US_received = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, 15507224.5, 15507224.5, 15507224.5, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, 333333.3333, 333333.3333, 
    333333.3333, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA), Total_US_required = c(NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, 20502064.83, 20502064.83, 20502064.83, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, 3070192, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, 49955895.25, 49955895.25, 49955895.25, 49955895.25, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 333333.3333, 
    333333.3333, 333333.3333, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), row.names = c(NA, 
200L), class = "data.frame")

0 个答案:

没有答案