Add horizontal lines from a vector to a ggplot uisng facet_grid

198 views Asked by At

I would like to add several horizontal lines from a vector to all the plots using facet_grid on the same position

The toy example is this one

 test <-  c(1,2,3,4)
 test_L <- rep(NA, 146)
 lines <- c(test , test_L )

       ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, col = Species))+
       geom_line()+
       stat_smooth()+
       geom_hline(aes(yintercept= lines)) +
       facet_grid(Species ~., scales = "free_y")

However, this gives me only the horizontal lines on one of the plots, not in all of them. Could you please tell me how I could achieve this?

0

There are 0 answers