gpt4 book ai didi

r - 没有ggplot2图正在工作: "Error in y[setdiff(names(y), names(x))] : object of type ' closure' is not subsettable"

转载 作者:行者123 更新时间:2023-12-04 04:10:16 25 4
gpt4 key购买 nike

我是R的新手,正在努力使ggplot2可靠地工作。即使是在其他地方复制的简单代码段也无法在我的机器上运行。

这:

library(ggplot2)
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) + geom_point()

给我:

Error in y[setdiff(names(y), names(x))] : object of type 'closure' is not subsettable



重要的是,这在昨天有效。我想不出任何改变。现在不是。

我已经重新安装了R,Rstudio和 ggplot2,但无济于事。我的猜测是某个地方存在版本控制问题,但不确定。

谢谢你的帮助。

更新

这是 sessioninfo()的输出:
R version 3.3.0 (2016-05-03)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.5 (Yosemite)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] ggrepel_0.5 scales_0.4.0 ggplot2_2.1.0

loaded via a namespace (and not attached):
[1] labeling_0.3 colorspace_1.2-6 plyr_1.8.3 tools_3.3.0
gtable_0.2.0
[6] Rcpp_0.12.5 grid_3.3.0 munsell_0.4.3

最佳答案

如果设置了无效的默认主题,则可以重现此错误消息。例如:

library(ggplot2)
theme_set(theme_bw) # improper usage of theme_set, should be theme_set(theme_bw())
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) + geom_point()

给我错误
Error in y[setdiff(names(y), names(x))] : 
object of type 'closure' is not subsettable


library(ggplot2)
theme_set(theme_bw()) # have now fixed theme_bw
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) + geom_point()

工作良好。

关于r - 没有ggplot2图正在工作: "Error in y[setdiff(names(y), names(x))] : object of type ' closure' is not subsettable",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37623483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com