将标签*行号*添加到绘图中

时间:2017-03-16 20:24:24

标签: r

如何修改此代码以显示一个图表 图表上的每个点都将其对应的行号作为标签。

inter <- seq(7.5, 21.5, 1)
LogDifference <- c("na",1.5,0.8,0.6,0.01,-0.57,-0.11,0.41,0.068,-0.19,-0.31,0.05,0.14,0.6,0.5)
S<-data.frame(inter,LogDifference)
plot(x = S$inter,S$LogDifference)

1 个答案:

答案 0 :(得分:1)

首先,请注意您的基本情节没有达到您想要的效果。 绘制的y值是数字1到14.我认为你想要的 LogDifference中的数值。你可以解决这个问题 首先将LogDifference转换为字符(这是一个因素),然后转换 数字。我只是遗漏了“na”。

之后,您可以使用text在点旁边放置标签。 完整的代码是:

inter <- seq(7.5, 21.5, 1)
LogDifference <- c("na",1.5,0.8,0.6,0.01,-0.57,-0.11,0.41,0.068,
     -0.19,-0.31,0.05,0.14,0.6,0.5)
S<-data.frame(inter,LogDifference)
plot(x = S$inter[-1], as.numeric(as.character(S$LogDifference[-1])))
text(x=inter[-1]+0.4, y=as.numeric(as.character(LogDifference[-1]))+0.05, labels=2:15)

Labeled graph