【问题标题】:Random data added when using `plot` in R在 R 中使用“绘图”时添加的随机数据
【发布时间】:2019-03-21 02:38:48
【问题描述】:

我偶然发现了这个,我不知道发生了什么。谁能解释一下?

plot(iris$Petal.Length,iris$foobar)

产生这个:

即使没有iris$foobar,甚至只是一个foobar 对象。这个 y 轴数据来自哪里?我在另一个 data.frame 中遇到过这种情况,所以这不是 iris 独有的(事实上,我在 iris 上尝试过,看看我的另一个 data.frame 是否有问题)。又怎么x轴被标记为“索引”?

版本数据: 平台 x86_64-w64-mingw32
拱 x86_64
操作系统 mingw32
系统 x86_64、mingw32
状态
专业 3
次要 4.3
2017 年
第 11 个月
第 30 天
svn 版本 73796
语言 R
version.string R 版本 3.4.3 (2017-11-30) 绰号吃风筝的树

loadedNamespaces()
 [1] "Rcpp"         "HistData"     "bindr"        "magrittr"    
 [5] "grDevices"    "tidyselect"   "munsell"      "wordcloud"   
 [9] "colorspace"   "R6"           "rlang"        "stringr"     
[13] "plyr"         "dplyr"        "tools"        "utils"       
[17] "grid"         "gtable"       "stats"        "datasets"    
[21] "yaml"         "lazyeval"     "assertthat"   "tibble"      
[25] "base"         "bindrcpp"     "purrr"        "RColorBrewer"
[29] "ggplot2"      "tidyr"        "graphics"     "glue"        
[33] "slam"         "stringi"      "compiler"     "pillar"      
[37] "methods"      "scales"       "lubridate"    "pkgconfig"   
[41] "Cairo" 

【问题讨论】:

    标签: r plot


    【解决方案1】:

    在我看来,data.frame 中似乎没有 foobar,因为您只调用 plot(iris$Petal.Length) 时会得到相同的情节。由于第二个参数为 null is.null(iris$foobar),它将被忽略....

    【讨论】:

      【解决方案2】:

      plot() 忽略了d$foobar,因为iris$foobarNULL

      它只是绘制花瓣长度,x 轴是索引。

      plot(iris$Petal.Length)plot(iris$Petal.Length, NULL) 比较。

      【讨论】:

      • 谢谢。怎么不报错?什么是索引?
      • 查看@HolgerBarlt 为什么没有错误。索引是行号。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-21
      • 1970-01-01
      相关资源
      最近更新 更多