I have the following data:
mydf = read.table(text="
name a b
x 10 15
y 20 25
z 35 45
", header = T)
I want to create a plot as follows:
I am not able to add horizontal lines from points to the vertical line at x=50. These lines (blue) have been manually drawn in the figure above. I tried following code but it does not work:
ggplot(mydf, aes(a, b)) + geom_point()+
geom_vline(xintercept=50)+
geom_line(aes(x=50,y=b, group=name))
Try geom_segment
:
ggplot(mydf, aes(a, b)) +
geom_point()+
geom_vline(xintercept=50) +
geom_segment(aes(x=a, xend=50, y=b, yend=b), colour="blue")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With