【问题标题】:How to use lwd for specific points如何针对特定点使用 lwd
【发布时间】:2016-01-31 03:51:33
【问题描述】:

我想更改 R Plot 中两点 [(4,1) 和 (5,0)] 之间的线的粗细。

x <- c(1, 2, 3, 4, 5, 6, 7, 8, 9)
y <- c(0, 1, 0, 1, 0, 1, 0, 1, 0)

plot(x, y, type="b", ann = FALSE, axes = FALSE, pch = 20, lwd=ifelse(x>=4 & x<=5, 3, 1))

但是,我只能使点更粗。我还需要使线条更粗。你们能告诉我我哪里错了吗?

我尝试了线条和线段。我得到一条触及两个点的线。但是,我需要较粗的线与其他线的长度相同。

使用lines解决

【问题讨论】:

    标签: r plot lines


    【解决方案1】:

    对于情节,lwd 不能接受向量。您可能想尝试改用lines

    plot(x, y, type="b", ann = FALSE, axes = FALSE, pch = 20)
    
    lines(x[4:5], y[4:5], lwd = 3, type = "b")
    

    【讨论】:

      【解决方案2】:

      分段采用 (x0,y0) 并绘制到 (x1,y1)

      segments(x[4],y[4],x[5],y[5], lwd=3)
      

      【讨论】:

      • 感谢您的回复。是否也可以使新行的长度与其他行相同。
      【解决方案3】:

      plot 本身并不能真正做你想做的事。您需要拨打plot,然后拨打segments

      XMIN = 4
      XMAX = 5
      
      plot(x, y, type="b", ann = FALSE, axes = FALSE, pch = 20)
      xinds = x>=XMIN & x<=XMAX
      segments(x[xinds][1:sum(xinds)-1],y[xinds][1:sum(xinds)-1],
               x[xinds][2:sum(xinds)],y[xinds][2:sum(xinds)], lwd=3)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-19
        • 1970-01-01
        • 2021-02-26
        • 2017-12-13
        • 2021-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多