Adding partial horizontal lines with ggplot2 in R

I have the following data:

mydf = read.table(text=" name ab x 10 15 y 20 25 z 35 45 ", header = T) 

I want to create a graph as follows:

plot example

I cannot add horizontal lines from dots to a vertical line at x = 50. These lines (blue) were manually drawn in the figure above. I tried the 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)) 
+6
source share
1 answer

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") 

plot

+9
source

Source: https://habr.com/ru/post/989007/


All Articles