【问题标题】:Adding Label *row number* into the Plot将标签*行号*添加到绘图中
【发布时间】:2017-08-08 05:17:25
【问题描述】:

我怎样才能修改这段代码来绘制一个图,以便它显示 图表上的每个点都将其对应的行号作为标签。

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)

【问题讨论】:

    标签: r


    【解决方案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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-03
      • 2016-07-09
      • 1970-01-01
      • 2011-01-22
      • 1970-01-01
      • 2014-03-06
      • 2015-12-28
      • 2012-03-04
      相关资源
      最近更新 更多