I have the following data.frame
and R-code
and i am trying to produce a bar graph
where precipation
on the secondary axis should be reversed.
library(tidyverse)
DF <- data.frame(Month = 1:12, Flow = c(1,2,5,30,45,50,40,25,15,10,4,1.2),
Prec = c(24,17,23,31,55,93,80,69,13,32,25,25))
ggplot(DF,aes(x = Month))+
geom_bar(aes(y = Flow), stat = "identity", color="blue", fill= "blue", width = 0.5)+
geom_bar(aes(y = Prec*0.5), stat = "identity", color="red", fill= "red", width = 0.5)+
scale_y_continuous("Streamflow", sec.axis = sec_axis(~ . /0.5, name = "Precipitation (mm)"), trans = "reverse")