My plot is almost ready, I just cannot reverse the secondary axis of a line (geom_line) plotted over a dodge barplot. My code so far:
coeff<--1/50
ggplot(coll,aes(Date,value,fill=variable))+
geom_bar(stat="identity",position="dodge")+
ylab("Precipitation")+xlab("Month")+ylim(0,900)+
geom_line(aes(x=Date,y=Temp/coeff,col="black"),col="black")+
geom_point(aes(x=Date,y=Temp/coeff,col="black"),col="black")+
scale_y_continuous(sec.axis = sec_axis(~.*coeff, name = "Temp"))
I just need the y axis at the right (Temp) to be reversed and start at the top from zero 0 to -15
This is the result I have now
And my dataframe looks something like this:
Date<-c("1/1/2019","2/1/2019","3/1/2019","4/1/2019","5/1/2019","6/1/2019","7/1/2019",
"8/1/2019","9/1/2019","10/1/2019","11/1/2019","12/1/2019")%>%data.frame()
names(Date)[names(Date) == "."] <- "Date"
Date<-as.POSIXct(Date$Date,format="%m/%d/%Y")
Month<-c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")%>%data.frame()
names(Month)[names(Month) == "."] <- "Month"
Temp<-c(NA,-3,-6,-13,-12,-6,-5,-1,-4,-7,-8,NA)%>%data.frame()
names(Temp)[names(Temp) == "."] <- "Temp"
variable<-c(rep("bar1",12,sep=","),rep("bar2",12,sep=","),rep("bar3",12,sep=","))%>%data.frame()
names(variable)[names(variable) == "."] <- "variable"
value<-rnorm(36,400,100)
coll<-cbind(Date,Month,Temp,variable,value)