Reputation: 713
I'd like to visualize data by using ggplot2, but instead of joining the dots directly, I'd like to join the dots like in the 2nd example of this image :
Question : How can I do that with ggplot2 ?
Edit : Your solution works well user20650 but the lines don't appear straight when I plot them into a pdf :
Do you know why ?
Upvotes: 1
Views: 262
Reputation: 25854
geom_step
should work here. The direction="vh"
directs the steps to vertical first then horizontal
# Some example data
dat <- data.frame(x = 0:2, y=c(3,1,2))
library(ggplot2)
ggplot(dat, aes(x, y)) + geom_point() + geom_step(direction="vh")
Upvotes: 2