I want to create a horizontal line going across two plots combined with the patchwork package.
library(ggplot2)
library(patchwork)
# Annotation after plot
p1 <- ggplot(mtcars, aes(x=disp,y=mpg))+
geom_point()
p2 <- ggplot(mtcars, aes(x=hp,y=mpg))+
geom_point()
# Want line across plots at y (mpg) of 15
p3 <- (p1+p2)+annotate("segment",x=-Inf,xend=Inf,y=15,yend=15)
p3
This method only puts the line across the last plot (p2).
Trying with putting the annotation with each plot.
# Annotation with each plot
p1 <- ggplot(mtcars, aes(x=disp,y=mpg))+
geom_point()+
annotate("segment",x=-Inf,xend=Inf,y=15,yend=15)
p2 <- ggplot(mtcars, aes(x=hp,y=mpg))+
geom_point()+
annotate("segment",x=-Inf,xend=Inf,y=15,yend=15)
p1+p2