R - 情节错误对象......未找到 [英] R - plotly error object ... not found
问题描述
我尝试运行带有 iris 数据集的示例行给出对象 '...' not found 错误.我需要在我的环境中检查特定的内容吗?
图书馆(情节)p <- plot_ly(iris, x = Petal.Length, y = Petal.Width,color = Species, mode = "markers")
<块引用>
plot_ly(iris, x = Petal.Length, y = Petal.Width, color = Species, 中的错误:未找到对象Petal.Length"
这恰好是已知的
引自 最新的 plotly 文档plotly 4.0 及以上:
<块引用>plot_ly() 现在需要一个公式(基本上是一个表达式,但在引用变量时带有 ~ 前缀).你不必使用公式来引用命名空间中存在的对象,但我推荐它,因为它有助于填充合理的轴/指南标题默认值(例如,将 plot_ly(z = 火山) 的输出与plot_ly(z = ~volcano) ).
I try to run a sample line with iris data set gives object '...' not found error. Is there any I need to check specific in my environment?
library(plotly)
p <- plot_ly(iris, x = Petal.Length, y = Petal.Width,color = Species, mode = "markers")
Error in plot_ly(iris, x = Petal.Length, y = Petal.Width, color = Species, : object 'Petal.Length' not found
This happen to be known issue reported to plotly. To fix your example you should add tilde "~" to the data frame columns names:
library(plotly)
p <- plot_ly(iris, x = ~Petal.Length, y = ~Petal.Width,color = ~Species, mode = "markers")
p
This should give you:
Quote from the latest plotly doc for plotly 4.0 and above:
plot_ly() now requires a formula (which is basically an expression, but with a ~ prefixed) when referencing variables. You do not have to use a formula to reference objects that exist in the namespace, but I recommend it, since it helps populate sensible axis/guide title defaults (e.g., compare the output of plot_ly(z = volcano) with plot_ly(z = ~volcano) ).
这篇关于R - 情节错误对象......未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!