LeonLara
LeonLara

Reputation: 61

Plotting lines between coordinates using ggplot2

I'm trying to plot the connecting lines for different sets of coordinates found in a file with the following format:(both coordinates have the same Y-value but different X-values)

Y1 X11 X12
Y2 X21 X22
Y3 X31 X32
.
.
.

I was able to find a way to do it using segments() in r. Since plotting the lines for those coordinates will produce thousands of lines, I would like to use ggplot2 for giving alpha levels to the line colors in order to check those areas in the plot that have a greater number of superimposed lines.

Upvotes: 2

Views: 2303

Answers (1)

user20650
user20650

Reputation: 25854

Im not sure if this is what you want:

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)

Upvotes: 2

Related Questions