R ggplot, which changes one axis of the plot when there is more than one plot in the plot, without affecting other plots

I have plotted a rainfall dataset using ggplot2. I need to print the sediment and flow data in the same graph I made with this

p <- ggplot(data=raw_data, aes(x=Hr, y=RF)) +
  geom_bar(stat="identity") 

p <- p + geom_line(aes(x= Hr, y=SF))

      

My question is how to flip the histogram upside down. I've already tried using ylim(60,0)

and scale_y_reverse

, which causes both graphs to flip. Any help.

+3


source to share


1 answer


try it



require(ggplot2)

df1 <- data.frame(x=c(1,2), y=c(3,4))
dfdummy <- data.frame(xx=c(1,2), yy=c(5,5))

 # here the arbitrary hang height is 5, see yy.

ggplot() +
  geom_bar(data=dfdummy, aes(x=xx, y=yy), stat="identity") + # dummy bars
  geom_bar(data=df1, aes(x=x, y=y), stat="identity", fill="white") + # overwriting dummy
  theme_classic() # theme w/o grid lines and background matching fill means invisible data

      

+1


source







All Articles