Reputation: 3805
I want the vertical lines to not go beyond the curve line after they intersect
Example data:
x <- 1:50
dat <- data.frame(x = x, y = 1 - exp(-x/43)^4)
ggplot(dat, aes(x = x, y = y)) +
geom_line() +
geom_vline(xintercept = c(10, 20, 30),
lty = "dashed")
Upvotes: 3
Views: 628
Reputation: 56149
Use geom_segment instead:
ggplot(dat, aes(x = x, y = y)) +
geom_line() +
geom_segment(aes(x = x, xend = x, y = min(dat$y), yend = y),
data = dat[ dat$x %in% c(10, 20, 30), ],
lty = "dashed")
Upvotes: 4