使用ggplot2在坐标之间绘制线条

时间:2013-06-22 22:31:14

标签: r ggplot2

我正在尝试使用以下格式绘制文件中找到的不同坐标集的连接线:(两个坐标具有相同的Y值但不同的X值)

Y1 X11 X12
Y2 X21 X22
Y3 X31 X32


点。

我能够在r中使用segments()找到一种方法。由于绘制这些坐标的线将产生数千条线,我想使用ggplot2为线颜色提供alpha级别,以便检查图中具有更多叠加线的区域。

1 个答案:

答案 0 :(得分:2)

我不确定这是不是你想要的:

library(ggplot2)

#some data
df<-data.frame(y=1:1000,x1=sample(1:100.1000,replace=T))
df$x2<-df$x1+sample(5:10,1000,replace=T)

ggplot()  + geom_segment(data=df,aes(x = x1, y = y, xend = x2, yend = y),colour="red",alpha=0.5)