【问题标题】:R Programming other alternatives for plotR编程绘图的其他替代方案
【发布时间】:2018-08-04 12:12:54
【问题描述】:

我想知道如何简化这两个:

plot (payroll,wins)
id = identify(payroll, wins,labels = code, n = 5)
plot (payroll,wins)
with(data, text(payroll, wins, labels = code, pos = 1, cex=0.5))

使用其他替代方法 - pch() 和 as.numeric()?

【问题讨论】:

  • 您根本没有使用id。或许可以用文字来解释你想要达到的目标?
  • 有什么方法可以使用 as.numeric() 获得相同的结果 - 可能略有不同,因为您可以使用 pch() 更改图标,但我不明白如何使用 as.numeric() ?
  • 我不清楚你想在这里做什么。绘制,识别点,绘制这些点?该代码对我来说毫无意义。您能否提供一个可重现的示例,并准确告诉我们您要实现的目标是什么?
  • 有没有使用 as.numeric 到 plot ?要点是我必须使用 as.numeric 才能达到相同的结果。
  • 对不起,我不明白你的意思。

标签: r


【解决方案1】:

不确定这是否更容易,但您在识别过程中更改 pch 如下(取自 R-help)。每次点击空白点都会变成实心点。

# data simulation
data <- data.frame(payroll = rnorm(10), wins = rnorm(10), code = letters[1:10])

identifyPch <- function(x, y = NULL, n = length(x), plot = FALSE, pch = 19, ...)
{
  xy <- xy.coords(x, y)
  x <- xy$x
  y <- xy$y
  sel <- rep(FALSE, length(x))
  while (sum(sel) < n) {
    ans <- identify(x[!sel], y[!sel], labels = which(!sel), n = 1, plot = plot, ...)
    if(!length(ans)) {
      break
    }
    ans <- which(!sel)[ans]
    points(x[ans], y[ans], pch = pch)
    sel[ans] <- TRUE
  }
  ## return indices of selected points
  which(sel)
}

if(dev.interactive()) { ## use it
  with(data, plot(payroll,wins))

  id = with(data, identifyPch(payroll, wins))
}

【讨论】:

    猜你喜欢
    • 2014-07-08
    • 2011-07-24
    • 1970-01-01
    • 2014-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-17
    • 1970-01-01
    相关资源
    最近更新 更多