R箭头标记了图上的数据点

Adi*_*hag 5 plot r

我希望用索引标记数据点 - 通过目视检查轻松识别索引号.

所以,例如,

x<-ts.plot(rnorm(10,0,1)) # would like to visually identify the data point indices easily through arrow labelling
Run Code Online (Sandbox Code Playgroud)

当然,如果有更好的方法来实现这一点,请建议

Jil*_*ina 5

您可以使用arrows功能:

set.seed(1); ts.plot(x <-rnorm(10,0,1), ylim=c(-1.6,1.6))  # some random data
arrows(x0=1:length(x), y0=0, y1=x, code=2, col=2, length=.1) # adding arrows
text(x=1:10, y=x+.1, 0, labels=round(x,2), cex=0.65) # adding text
abline(h=0) # adding a horizontal line at y=0
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明