简体   繁体   English

Rbokeh条形图通过X轴重新排序

[英]Rbokeh barplot reordered by x-axis

Here is a simple example of barplot expressed in Rbokeh. 这是用Rbokeh表示的barplot的简单示例。

library(rbokeh)

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

Result are shown as below 结果如下图所示

在此处输入图片说明

Question 1) I want to plot bars, reordered on x-axis by yield in descending order 问题1)我想绘制条形图,并按收益率降序在x轴上重新排序

I know that there's simple way of doing this in ggplot with 'reorder' function, but have no idea how to do this in Rbokeh. 我知道在ggplot中使用“重新排序”功能有一种简单的方法,但是不知道如何在Rbokeh中执行此操作。

How can I do this? 我怎样才能做到这一点?

Question 2) Running the code above, I can see this error message, what does this mean and how can I solve this problem? 问题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.

For the first question: you can control the ordering of categorical axes by specifying the order in the xlim * . 对于第一个问题:您可以通过在xlim *中指定顺序来控制分类轴的顺序。 But first you should group "variety". 但是首先您应该将“品种”分组。 I did: 我做了:

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

Then, generate the plot: 然后,生成图:

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)

For the second question, perhaps you can refer to this . 对于第二个问题,也许您可​​以参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM