Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何在添加特定'的所有正值和负值后绘制柱状图;年份';在geom_col?_R_Ggplot2_Geom Col - Fatal编程技术网

R 如何在添加特定'的所有正值和负值后绘制柱状图;年份';在geom_col?

R 如何在添加特定'的所有正值和负值后绘制柱状图;年份';在geom_col?,r,ggplot2,geom-col,R,Ggplot2,Geom Col,我有一个数据框包含了1948-2013年期间的一些信息。每年还包含4季的数据。现在,年份有时包含正和负数据。我的数据样本 YEAR Region temp_avg_max temp_avg_min temp_dif_avg_max whole_avg_min_temp <int> <chr> <dbl> <dbl> <d

我有一个
数据框
包含了1948-2013年期间的一些信息。每年还包含
4季的数据。现在,年份有时包含
数据。我的数据样本

   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
你可以看看我的图表

但是,我希望以这种方式为特定的
区域
绘制它们(将添加所有负值和正值),然后绘制


ggplot2 2.2.0
中,任何指导原则都是值得赞赏的负堆叠是可能的

只需删除
geom_文本
并更改一些次要内容。找到代码

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)
plot_diff_max_temp_vs_year_region_col
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)