ggplot“重命名错误”
更新我已经在下面发布了我的解决方案,罪魁祸首是我自己的rename
函数,它覆盖了reshape::rename
我一直在使用ggplot R包直到今天都没有遇到什么麻烦。今天,我使用以前有效的代码时遇到错误,当我将其调试到最小工作示例时,它仍然给出错误;
如果我这样做:
library(ggplot2)
d<- data.frame(x=1:3,y=1:3)
ggplot(data=d) + geom_line(aes(x,y))
返回以下错误:
Error in rename(x, .base_to_ggplot) :
unused argument(s) (.base_to_ggplot)
回溯是:
6: rename(x, .base_to_ggplot)
5: rename_aes(aes)
4: aes()
3: structure(list(data = data, layers = list(), scales = Scales$new(),
mapping = mapping, options = list(), coordinates = CoordCartesian$new(),
facet = FacetGrid$new(), plot_env = environment), class = "ggplot")
2: ggplot.data.frame(data = d, aes = c(x, y))
1: ggplot(data = d, aes = c(x, y))
使用 rm(list=ls()) 删除所有对象后不会发生错误,但我仍然不清楚是什么对象导致了这个错误或者为什么 - 我怎样才能解决这个问题?
有谁知道可能出了什么问题?
update I have posted my solution below, the culprit was my own rename
function that overrode reshape::rename
I have been using the ggplot R package with little trouble until today. Today, I get an error using code that has previously worked, and when I debug it to the minimal working example, it still gives an error;
If I do this:
library(ggplot2)
d<- data.frame(x=1:3,y=1:3)
ggplot(data=d) + geom_line(aes(x,y))
The following error is returned:
Error in rename(x, .base_to_ggplot) :
unused argument(s) (.base_to_ggplot)
The traceback is:
6: rename(x, .base_to_ggplot)
5: rename_aes(aes)
4: aes()
3: structure(list(data = data, layers = list(), scales = Scales$new(),
mapping = mapping, options = list(), coordinates = CoordCartesian$new(),
facet = FacetGrid$new(), plot_env = environment), class = "ggplot")
2: ggplot.data.frame(data = d, aes = c(x, y))
1: ggplot(data = d, aes = c(x, y))
The error does not occur after removing all objects using rm(list=ls())
, but it is still not clear to me what object is causing this error or why - how can I figure this out?
Does anyone know what may have gone wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我无法返回您上面发布的相同错误消息。运行代码片段时,我收到以下错误:
因此,
geom_pointrange()
需要ymin
和ymax
的参数。我将让您填写有关这些参数应包含哪些内容的相关信息,但此代码执行:ggplot(data=d) + geom_pointrange(aes(x,y, ymin = y - 。 5、ymax = y + .5))
I'm not able to return the same error message that you've posted above. When running your code snippet, I'm getting the following error:
Accordingly,
geom_pointrange()
is expecting arguments forymin
andymax
. I'll leave it up to you to fill in your pertinent information for what should go into those parameters, but this code executes:ggplot(data=d) + geom_pointrange(aes(x,y, ymin = y - .5, ymax = y + .5))
该问题是因为 ggplot2 不使用命名空间而引起的 - 这将在下一个版本中修复。
The problem is caused because ggplot2 doesn't use namespaces - this will be fixed in the next release.
该错误是由其中一个对象引起的(感谢@Chase 的指针)。
这是我调试并找到罪魁祸首的方法。重要的部分是使用
try()
函数,尽管出现错误,但仍能保持 for 循环运行。这导致了以下输出:
啊哈!这是我自己的函数
rename
导致了错误,因为ggplot2
依赖于reshape::rename
。解决方案:重命名新的
rename
函数...将来如何防止这种情况发生?也许研究一下命名空间的使用。The error was caused by one of the objects (thanks to pointers from @Chase).
Here is how I debugged and found the culprit. The important part was to use the
try()
function that keeps the for loop running despite errorsThis resulted in the following output:
aha! it was my own function
rename
that caused the error, sinceggplot2
relies onreshape::rename
.Solution: rename the new
rename
function... how to prevent this in the future? Perhaps study up on the use of namespaces.