R - plotly error object … not found

。_饼干妹妹 提交于 2020-12-05 07:18:29

问题


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


回答1:


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) ).



来源:https://stackoverflow.com/questions/39915018/r-plotly-error-object-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!