使用“重新排序”时,根据数字向量着色不起作用在 x 轴上
library(dplyr)
library(plotly)
# data frame
Title = c('Titanic', 'Avatar', 'Jurassic World')
Profit = c(458672302, 523505847, 502177271)
df = data.frame(Title, Profit)
基本上,我正在尝试根据PROUT
列来color
。而且,如果未订购,它可以工作图1
# X axis not ordered (working)
plot_ly(df, x = ~Title,
y = ~Profit,
color = ~Profit,
type = 'bar')
但是当我尝试重新订购时/code> <代码> x axis
(看起来像 this ),它返回错误,可能是因为它是 factor :
# X axis reordered (not working)
plot_ly(df, x = ~reorder(Title, -Profit) %>% as.character(),
y = ~Profit,
color = ~Profit,
type = 'bar')
summary.factor中的错误(c(3L,1L,2L),na.rm = true): “范围”对因素没有意义 另外:警告消息: textfont.color(尚未)支持数据数组
是否有任何提示?
library(dplyr)
library(plotly)
# data frame
Title = c('Titanic', 'Avatar', 'Jurassic World')
Profit = c(458672302, 523505847, 502177271)
df = data.frame(Title, Profit)
Basically, I'm trying to color
the bars according to the Profit
column. And when it's not ordered, it works figure 1
# X axis not ordered (working)
plot_ly(df, x = ~Title,
y = ~Profit,
color = ~Profit,
type = 'bar')
But when I try to reorder
the x axis
(to look like this), it returns an error, probably because it's a factor:
# X axis reordered (not working)
plot_ly(df, x = ~reorder(Title, -Profit) %>% as.character(),
y = ~Profit,
color = ~Profit,
type = 'bar')
Error in Summary.factor(c(3L, 1L, 2L), na.rm = TRUE) :
‘range’ not meaningful for factors
In addition: Warning message:
textfont.color doesn't (yet) support data arrays
Does anyone have any tips?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码对我来说效果很好:
输出:
这是我的
sessioninfo
:因此您可以使用
sessioninfo()
检查您的会话你的控制台并检查是否你的包裹是对的。Your code works fine for me:
Output:
This is my
sessioninfo
:So what you can do is check your session using
sessioninfo()
in your console and check if you packages are right.