如何将 lwd 用于特定点

How to use lwd for specific points

我想更改 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解决

段取 (x0,y0) 并绘制到 (x1,y1)

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

对于绘图,lwd 不能接受向量。您可能想尝试使用 lines 而不是

plot(x, y, type="b", ann = FALSE, axes = FALSE, pch = 20)

lines(x[4:5], y[4:5], lwd = 3, type = "b")

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)