【问题标题】:Plotting lines between coordinates using ggplot2使用ggplot2在坐标之间绘制线
【发布时间】:2013-06-22 22:31:13
【问题描述】:

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

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

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

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

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

    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)
    

    【讨论】:

      猜你喜欢
      • 2020-03-06
      • 1970-01-01
      • 2023-03-10
      • 2021-11-26
      • 2011-11-21
      • 2019-06-27
      • 2016-02-29
      • 1970-01-01
      • 2020-02-11
      相关资源
      最近更新 更多