I am trying to plot two flows and one rainfall data in one graph. I have broke it up into top and bottom parts as shown in the following pic. Here I have two issues with this plots and spent ages but cannot solve it.
- Why the observed flow always in black, even I have set it up as blue? Did I accidentally used some other arguments to overwrite it?
The most importantly is, how do I able to add a legend for the bottom plot? I tried many different codes but they don't seem to work for me.
x = data.frame(date = Date, rain = Obs_rain, obsflow = Obs_flow,simflow=Sim_flow) g.top <- ggplot(x, aes(x = date, y = rain, ymin=0, ymax=rain)) + geom_linerange() + scale_y_continuous(trans = "reverse") + theme_bw() + theme(plot.margin = unit(c(1,5,-30,6),units="points"), axis.title.y = element_text(vjust =0.3)) + labs(x = "Date",y = "Rain(mm)") g.bottom <- ggplot(x, aes(x = date, y = obsflow, ymin=0, ymax=obsflow), colour = "blue",size=0.5) + geom_linerange() + #plot flow geom_linerange(aes(y = simflow, ymin=0, ymax=simflow), colour = "red", size =0.5)+ labs(x = "Date", y = "River flow (ML/day)") + theme_classic() + theme(plot.background = element_rect(fill = "transparent"), plot.margin = unit(c(2,0,1,1),units="lines")) grid.arrange(g.top,g.bottom, heights = c(1/5, 4/5))
Update:
I have resolved the issue with blue line colour. I accidently put arguments in the wrong place. But I'm still struggling with the legend.
g.bottom <- ggplot(x, aes(x = date, y = obsflow, ymin=0, ymax=obsflow)) +
geom_linerange(colour = "blue",size=0.5) + #plot flow