First create an empty plotting surface
plot(0,0, xlim=c(0,1), ylim=range(c(0, x1,x2)), type="n", xaxt="n")
axis(side=1, at=c(0,1), labels=c("x1","x2"))
Then add draw the segments
segments(0, x1, 1, x2)
and optionally points
points(rep(0, length(x1)), x1);
points(rep(1, length(x2)), x2)
If you want to use ggplot, it would make more sense to change your data format though
dd <- data.frame(id=seq_along(x1), x1=x1, x2=x2)
library(ggplot2)
ggplot(dd) + geom_segment(aes(y=x1, yend=x2), x=0, xend=1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.