Hi,
This is the final output I produce. It was good. Just a little bit I have to add to be the same as sample picture (above).
- I want to add a dashed line horizontally across the datetime
- And would like to add vertical smooth line.
Here is my code.
p1 <- ggplot(data=df,aes(x=datetime, y=P_Rain_mm))+
geom_bar(stat="identity",width =2.0,color="black")+
labs(y= "Rainfall (mm) ", x="Datetime")
p1
p1<- p1+
#Top x axis with no labels and title
scale_x_datetime(sec.axis = dup_axis(labels = NULL, name =element_blank())) +
#Right y axis with no labels and title
scale_y_continuous(sec.axis = dup_axis(labels = NULL, name=element_blank()))+
theme(
axis.ticks.length.x.top = unit(-5, "pt"),
#Direction of ticks (negative value means it will be inward)
axis.ticks.length.y.right=unit(-5,"pt"),
panel.grid.minor = element_blank(),
panel.background = element_rect(fill = "white", colour = "grey50")
)
p1
p1<- p1 +labs(x = NULL)+
theme(axis.text.x.bottom = element_blank())
p1
p2 <- ggplot(data = df,aes(x=datetime,y=Mg_CO2_ha_yr_exp_flux,group=month(datetime))) +
geom_line(aes(color=micro.form))+
labs(y= "Mg_CO2_ha_yr ", x="Datetime")
p2
p2<- p2+#Top x axis with no labels and title
scale_x_datetime(sec.axis = dup_axis(labels = NULL, name =element_blank())) +
#Right y axis with no labels and title
scale_y_continuous(sec.axis = dup_axis(labels = NULL, name=element_blank()))+
theme(
axis.ticks.length.x.top = unit(-5, "pt"),
#Direction of ticks (negative value means it will be inward)
axis.ticks.length.y.right=unit(-5,"pt"),
#Legend position inside the plot
legend.position = c(.99, .99),
legend.justification = c("right", "top"),
#Line around legend plate
legend.background = element_rect(color = "grey50"),
panel.grid.minor = element_blank(),
panel.background = element_rect(fill = "white", colour = "grey50")
)
p2
p2<- p2 +labs(x = NULL)+
theme(axis.text.x.bottom = element_blank())
p3 <- ggplot() +
geom_line(data = df,aes(x=datetime,y=RH_1_1_1.x, group=month(datetime)))+
labs(y= "Rel_Hum ", x="Datetime")+
theme(legend.position= "none")
p3
p3<- p3 +
#Top x axis with no labels and title
scale_x_datetime(sec.axis = dup_axis(labels = NULL, name =element_blank())) +
#Right y axis with no labels and title
scale_y_continuous(sec.axis = dup_axis(labels = NULL, name=element_blank()))+
theme(
axis.ticks.length.x.top = unit(-5, "pt"),
#Direction of ticks (negative value means it will be inward)
axis.ticks.length.y.right=unit(-5,"pt"),
panel.grid.minor = element_blank(),
panel.background = element_rect(fill = "white", colour = "grey50")
)
p3
p3<- p3 +labs(x = NULL)+
theme(axis.text.x.bottom = element_blank())
p4 <- ggplot() +
geom_line(data = df,aes(x=datetime,y=SWC_1_1_1.x,group=month(datetime)))+
labs(y= "SWC ", x="Datetime")
p4
p4 <- p4 +
#Top x axis with no labels and title
scale_x_datetime(sec.axis = dup_axis(labels = NULL, name =element_blank())) +
#Right y axis with no labels and title
scale_y_continuous(sec.axis = dup_axis(labels = NULL, name=element_blank()))+
theme(
axis.ticks.length.x.top = unit(-5, "pt"),
#Direction of ticks (negative value means it will be inward)
axis.ticks.length.y.right=unit(-5,"pt"),
panel.grid.minor = element_blank(),
panel.background = element_rect(fill = "white", colour = "grey50")
)
p4
p4<- p4 +labs(x = NULL)+
theme(axis.text.x.bottom = element_blank())
p4
p5 <- ggplot() +
geom_line(data = df,aes(x=datetime,y=WTD_1_1_1.x, group=month(datetime)))+
labs(y= "WTD ", x="Datetime")
p5
p5<- p5 +
#Top x axis with no labels and title
scale_x_datetime(sec.axis = dup_axis(labels = NULL, name =element_blank())) +
#Right y axis with no labels and title
scale_y_continuous(sec.axis = dup_axis(labels = NULL, name=element_blank()))+
theme(
axis.ticks.length.x.top = unit(-5, "pt"),
#Direction of ticks (negative value means it will be inward)
axis.ticks.length.y.right=unit(-5,"pt"),
panel.grid.minor = element_blank(),
panel.background = element_rect(fill = "white", colour = "grey50")
)
p5
library(gridExtra)
ggarrange(p1, p2,p3, p4,p5,
ncol = 1, nrow= 5)