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)) +

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.


source to share

1 answer

try it


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




All Articles