在 R 中使用 `plot` 时添加的随机数据 [英] Random data added when using `plot` in R
问题描述
我偶然遇到了这个,我不知道发生了什么.谁能解释一下?
I came across this by accident, and I have no idea what's going on. Can anyone explain this?
plot(iris$Petal.Length,iris$foobar)
产生这个:
即使没有 iris$foobar
,甚至只是一个 foobar
对象.这个 y 轴数据来自哪里?我在另一个 data.frame 中遇到过这个问题,所以这不是 iris 独有的(实际上,我在 iris 上尝试过,看看我的其他 data.frame 是否有问题).为什么 x 轴被标记为索引"?
Even though there is no iris$foobar
, or even just a foobar
object. Where is this y-axis data coming from? I've encountered this with another data.frame, so this is not unique to iris (in fact, I tried it on iris to see if there was something amiss with my other data.frame). And how come the x-axis is labeled as "Index"?
版本数据:平台 x86_64-w64-mingw32
拱形 x86_64
操作系统 mingw32
系统 x86_64,mingw32
状态
大三
次要 4.3
2017年
11月
第 30 天
SVN 修订版 73796
语言 R
version.string R 版本 3.4.3 (2017-11-30)昵称吃风筝的树
Version data:
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 4.3
year 2017
month 11
day 30
svn rev 73796
language R
version.string R version 3.4.3 (2017-11-30)
nickname Kite-Eating Tree
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"
推荐答案
d$foobar
被 plot()
忽略,因为 iris$foobar
是 NULL
.
d$foobar
is being ignored by plot()
, because iris$foobar
is NULL
.
它只是绘制花瓣长度,x 轴为索引.
It's simply plotting the petal length, with on the x-axis the index.
与 plot(iris$Petal.Length)
或 plot(iris$Petal.Length, NULL)
比较.
这篇关于在 R 中使用 `plot` 时添加的随机数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!