【问题标题】:Pairs function doesn't work in RPairs 函数在 R 中不起作用
【发布时间】:2012-09-21 01:26:23
【问题描述】:

我正在尝试从 alr3 包中绘制钞票数据框。我的 pair 函数抛出错误,并且在执行时没有给出正确的绘图。有人可以告诉我这里出了什么问题吗?谢谢。

基本上我正在尝试编写代码以从“alr3”包中存在的“钞票”数据框中找出所有假钞。

代码:-

pairs(banknote[,-1],panel=
function(x,y,fake){
xy <- cbind(x,y)
points(xy[fake==0,],pch=15)
points(xy[fake==1,],pch=0)
}, fake=Y)

错误:-

Error in points(xy[fake == 0, ], pch = 15) : 
  (subscript) logical subscript too long
In addition: Warning messages:
1: In plot.window(...) : "fake" is not a graphical parameter
2: In plot.xy(xy, type, ...) : "fake" is not a graphical parameter
3: In title(...) : "fake" is not a graphical parameter
4: In plot.window(...) : "fake" is not a graphical parameter
5: In plot.xy(xy, type, ...) : "fake" is not a graphical parameter
6: In title(...) : "fake" is not a graphical parameter
7: In axis(side = side, at = at, labels = labels, ...) :
  "fake" is not a graphical parameter

【问题讨论】:

    标签: r function


    【解决方案1】:

    呼应@DWin,尚不清楚Y 是什么,因为它会尝试从您的工作区获取Y

    如果您的意思是在banknote 中通过Y 列设置pch,那么以下将起作用

    pairs(banknote[,-c(1,7)], 
      panel = function(x,y,...){
        points(x,y,pch = ifelse(as.logical(banknote$Y), 0,15))})
    

    如果您不想引用data.frame 和使用$ 的列,那么您可以将所有内容包装在with(banknote, ...) 语句中,然后R 将在banknote 中查找以首先查找变量

    所以以下将起作用

    with(banknote, pairs(list(Left = Left, Right = Right, Bottom = Bottom, 
            Top = Top, Diagonal = Diagonal), 
          panel = function(x,y) points(x,y, pch= ifelse(as.logical(Y),0,15))) 
    

    【讨论】:

    • Y是来自钞票数据框的类属性。
    • attributeR 中具有特定含义,class 也是如此 - 正如您的陈述所代表的那样,它可能意味着任何东西。如果您的意思是 Ydata.frame banknote 中的 column,那就这么说吧! - 我的回答是针对这种情况的。
    【解决方案2】:

    错误:在评估完成时显然是length(fake) &gt; nrow(xy)

    警告:您的 'fake=Y' 参数在花括号之外,因此它被解释为传递给对的参数。我无法告诉您您期望它做什么,并且您没有显示工作区中可能存在的数据,所以... ???

    【讨论】:

    • 如果没有 dput() 对您修改过的数据框进行处理,这可能意味着除了您所说的之外的几乎任何内容。几乎可以肯定它不是attribute
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-06
    • 2016-08-07
    • 1970-01-01
    • 1970-01-01
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多