0

这是一个用 Rbokeh 表示的简单条形图示例。

library(rbokeh)

# total yield per variety
figure() %>%
  ly_bar(variety, yield, data = lattice::barley, hover = TRUE) %>%
  theme_axis("x", major_label_orientation = 90)

结果如下图

在此处输入图像描述

问题 1) 我想绘制条形图,在 x 轴上按产量按降序重新排序

我知道在 ggplot 中有一种简单的方法可以使用“重新排序”功能,但不知道如何在 Rbokeh 中做到这一点。

我怎样才能做到这一点?

问题2) 运行上面的代码,我可以看到这个错误信息,这是什么意思,我该如何解决这个问题?

Warning messages:
1: In structure(x, class = unique(c("AsIs", oldClass(x)))) :
  Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.
2: In structure(x, class = unique(c("AsIs", oldClass(x)))) :
  Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.
3: In structure(x, class = unique(c("AsIs", oldClass(x)))) :
  Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.
4: In structure(x, class = unique(c("AsIs", oldClass(x)))) :
  Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.
5: In structure(x, class = unique(c("AsIs", oldClass(x)))) :
  Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.
6: In structure(x, class = unique(c("AsIs", oldClass(x)))) :
  Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.
7: In structure(x, class = unique(c("AsIs", oldClass(x)))) :
  Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
  Consider 'structure(list(), *)' instead.
4

1 回答 1

2

xlim对于第一个问题:您可以通过在*中指定顺序来控制分类轴的顺序。但首先你应该对“品种”进行分组。我做了:

barley_data <- lattice::barley %>% 
  group_by(variety) %>% 
  summarise(yield = sum(yield))

然后,生成图:

figure(xlim = barley_data$variety[order(-barley_data$yield)]) %>%
  ly_bar(variety, yield, data = barley_data, hover = TRUE) %>%
  theme_axis("x", major_label_orientation = 90)

对于第二个问题,或许可以参考这个

于 2019-02-13T06:20:22.793 回答