I am trying to restrict the ranges of geom_abline. In the plot below, I would like the red line to stop at the xvalue 5 and the blue line to start at the value 5 (in the picture, I marked by hand the segments that need to be removed).
obs: I understand that aes
and slope
can not be used together, but still put it in the code, as a form of pseudocode, to clarify what I wanted ggplot2 to let me do.
library(tidyverse)
d <- data.frame(x=1:10,y=2:11)
d %>% ggplot(aes(x,y)) + geom_point() +
geom_abline(aes(xmax=5),slope = 1,color='red') +
geom_abline(aes(xmin=5),slope = 1,intercept = 3,color='blue')
The R outputs the warning:
Warning messages:
1: geom_abline(): Ignoring `mapping` because `slope` and/or `intercept` were provided.
2: geom_abline(): Ignoring `mapping` because `slope` and/or `intercept` were provided.