Rbokeh барплот переупорядочен по оси х - PullRequest
0 голосов
/ 30 января 2019

Вот простой пример графика, выраженного в Rbokeh.

library(rbokeh)

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

Результат показан ниже:

enter image description here

Вопрос 1) Я хочу построить бары, переупорядоченные по оси x по доходности в порядке убывания

Я знаю, что есть простой способ сделать это в ggplot с функцией 'reorder', но не имеюИдея, как это сделать в 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.

1 Ответ

0 голосов
/ 13 февраля 2019

По первому вопросу: вы можете управлять порядком категориальных осей, указав порядок в 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)

По второму вопросу, возможно, вы можете обратиться к this .

...