Hi.
As image illustrates, my barplot are not symmetrical in terms of width of bars, due to different number of observations, and different timespans for the individual years (2015, 2016 and 2018). I want the bars to be of equal size, but defining the width (width=) it becomes very messy.
Besides, for some unknown reason, the dateformat changes in 2018, where i suddenly only have months on the x axis , and not months+day as the previous years.
I've tried everything i could think off, including the functions gap.plot, gap.barplot and axis.break from the plotrix package (v3.7-6), but it dosent work with my ggplot.
library(tidyverse)
library(rmarkdown)
library(readxl)
library(dplyr)
library(tidyr)
library(lubridate)
library(reshape2)
library (ggthemes)
library(ggpubr)
library(plotrix)
library(scales)
#printing dataframe
print(gapl151618_wetCS)
N_ug_m2_h se_graph Date Trt Year
<dbl> <dbl> <date> <chr> <chr>
0.59172415 1.1529715 2018-06-15 C 2018
0.79847845 0.5764257 2018-07-01 C 2018
-2.02633456 -1.8041389 2018-09-19 C 2018
2.03877800 2.2450879 2018-06-15 S 2018
-1.19586851 -1.9191906 2018-07-01 S 2018
0.00776147 0.5356943 2018-09-19 S 2018
6.99500000 2.2524320 2016-07-07 C 2016
7.97983333 2.6705785 2016-07-18 C 2016
2.98933333 2.3721254 2016-08-01 C 2016
-1.65866667 -1.1795099 2016-08-15 C 2016
5.52157486 1.4964004 2015-08-06 C 2015
5.05983333 3.2670861 2016-07-07 S 2016
7.28733333 1.5233716 2016-07-18 S 2016
3.82466667 3.5809984 2016-08-01 S 2016
0.30750000 1.4447466 2016-08-15 S 2016
-0.09014181 -3.8432439 2015-08-06 S 2015
#creating plot
ggplot(gapl151618_wetCS, aes(x=Date , y=N_ug_m2_h, fill=Trt))+
geom_hline (yintercept=0, color = "black", linetype = 3 ) +
facet_wrap(~Year, scales = "free_x") +
geom_bar(position = position_dodge2 (width = 1), stat = "identity", colour="black", size=.3) +
geom_errorbar(aes(ymin=N_ug_m2_h, ymax=N_ug_m2_h+se_graph, group = Trt), position = position_dodge2 ()) +
ylab(expression(~mu~g~N[2]*O-N~~m^{-2}~h^{-1})) +
xlab("Date") +
ggtitle(expression(N[2]*O~fluxes~wet~tundra~2015~","~2016~and~2018))
Defining width on geom_bar
theme_set(
theme_bw()+
theme(legend.position = "right",
plot.title = element_text (hjust = 0.5, vjust = 1, size = 15),
axis.text.x = element_text (angle = 60, hjust = 1)))
ggplot(gapl151618_wetCS, aes(x=Date , y=N_ug_m2_h, fill=Trt))+
geom_hline (yintercept=0, color = "black", linetype = 3 ) +
facet_wrap(~Year, scales = "free_x") +
geom_bar(position = position_dodge2 (width = 1), stat = "identity", colour="black", size=.3, width = 1) +
geom_errorbar(aes(ymin=N_ug_m2_h, ymax=N_ug_m2_h+se_graph, group = Trt), position = position_dodge2 ()) +
ylab(expression(~mu~g~N[2]*O-N~~m^{-2}~h^{-1})) +
xlab("Date") +
ggtitle(expression(N[2]*O~fluxes~wet~tundra~2015~","~2016~and~2018))