Ophelie
Ophelie

Reputation: 713

R ggplot : join point by

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 :

Dots Joining

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 :

enter image description here

Do you know why ?

Upvotes: 1

Views: 262

Answers (1)

user20650
user20650

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

Related Questions