I'm trying to reproduce a simple lineplot, but there's a part of it that I don't know the proper term for or how to reproduce in ggplot2. It looks like this:
As you can see, there's a purple line that is striped and goes horizontal from the x-axis up to where the striped line and the line plot intersects, and then it turns into a filled line from the intersection point to the y-axis. What is this called? Is there an easy way of doing this in ggplot2? Something similar to geom_abline?
In order to make the intersection you need at least one number, I can confirm the number set is X=100.
I've tried making a solution using BOD data with geom_line, but it doesn't line up properly:
bod_intersect_time <- (BOD %>% mutate(demand=round(demand)) %>% filter(demand==10))$Time
ggplot() +
geom_line(data=BOD, aes(x=Time, y=demand)) +
geom_line(data=data.frame(Time=c(0, bod_intersect_time), demand=c(10,10)), aes(x=Time, y=demand, color="line", linetype="full") ) +
geom_line(data=data.frame(Time=c(bod_intersect_time, bod_intersect_time), demand=c(10, 0 )), aes(x=Time, y=demand, color="line", linetype="striped"))
Turns into this:
Is there a better way?
Update: Thanks to @Axeman I got the last piece of the puzzle to fix my code:
bod_intersect_time <- approx(BOD$demand, BOD$Time, 10)$y
But I still think there should be an easier way, shouldn't it just be something like geom_intersects(data=BOD, y=10)
?