在geom_col中为特定“年份”添加所有正负值后,如何绘制柱形图?

问题描述

我有一个data frame,其中包含一段时间(1948-2013)的一些信息。每年还包含4 season方面的数据。现在有时,年份包含positivenegative数据。我的数据样本

   YEAR Region               temp_avg_max temp_avg_min temp_dif_avg_max whole_avg_min_temp
     <int> <chr>                       <dbl>        <dbl>            <dbl>              <dbl>
     1  1948 Central egion                33.1         20.6          -0.400              -0.516
     2  1948 Eastern Region               32.7         19.1          -0.775              -2.08 
     3  1948 northern Region              33.5         20.2           0.0124             -0.970
     4  1948 northsouthern Region         33.5         21.3           0.0443              0.154
     5  1948 northwestern Region          31.6         20.9          -1.88               -0.232
     6  1948 Southeastern Region          32.5         21.8          -0.958               0.676
     7  1949 Central egion                33.1         20.6          -0.400              -0.516
     8  1949 Eastern Region               32.7         19.1          -0.775              -2.08 
     9  1949 northern Region              33.5         20.2           0.0124             -0.970
     10 1949 northsouthern Region         33.5         21.3           0.0443              0.154
     11 1949 northwestern Region          31.6         20.9          -1.88               -0.232
     12 1949 Southeastern Region          32.5         21.8          -0.958               0.676

现在我想画一个column graph,我也做了。我的代码如下

plot_diff_max_temp_vs_year_region_col <- ggplot(data=diff_max_temp[diff_max_temp$YEAR %in% c(1948,1960,1972,1984,1996,2008,2013),],aes(x=Region,y=temp_dif_avg_max,fill=factor(YEAR)))+
 geom_col(position="identity",width = 0.5)+
 geom_text(aes(label=sprintf("%0.1f",round(year_wise_region_max_temp,digits = 2))),position=position_dodge(width=0.9),vjust=-0.50)+
 theme_minimal()+
 xlab("Region")+
 ylab("Temperature")+
 ggtitle("Max Temp with 12 years moving ") 

您可以在听online plot link

的同时查看我的图表

但是,我想以此方式为特定的Region绘制它们(将添加所有负值和正值),然后绘制column

任何指导方针都值得赞赏

解决方法

ggplot2 2.2.0negative stacking是可能的。

只需删除geom_text并更改一些细微的内容即可。查找代码

plot_diff_max_temp_vs_year_region_col <- 
ggplot(data=diff_max_temp[diff_max_temp$YEAR %in% c(1948,1960,1972,1984,1996,2008,2013),]
                                       )+
geom_col(aes(x=Region,y=temp_dif_avg_max,fill=factor(YEAR)))+
 theme_minimal()+
 xlab("Region")+
 ylab("Temperature")+
 ggtitle("Max Temp with 12 years moving ") 
ggplotly(plot_diff_max_temp_vs_year_region_col)

我不确定,但是您可以查看此链接Link