R - 在分组的 hchart 中排列条形图

R - arrange bars in grouped hchart

我正在尝试创建一个分组的 highcharts 条形图,其中的条形图按字母顺序排列。

下面的示例显示了我正在尝试做的事情:

library(highcharter)

#create dataframe pokemon
pokemon <- pokemon <- structure(list(type_1 = c("poison", "poison", "poison", "poison", 
                                     "rock", "rock", "rock", "rock", "rock", "rock", "rock", "rock", 
                                     "rock", "poison", "rock", "rock", "rock", "rock", "rock", "rock", 
                                     "rock", "rock", "rock", "rock", "rock", "poison", "poison", "poison", 
                                     "poison", "poison", "poison", "rock", "rock", "rock", "rock", 
                                     "rock", "rock", "poison", "poison", "rock", "rock", "rock", "rock", 
                                     "rock")
                          , type_2 = c("ground", "ground", "flying", "flying", "ground", 
                                       "ground", "ground", "ground", "water", "water", "water", "water", 
                                       "flying", "flying", "ground", "ground", "dark", "psychic", "psychic", 
                                       "grass", "grass", "bug", "bug", "steel", "steel", "dark", "dark", 
                                       "bug", "dark", "fighting", "fighting", "steel", "flying", "flying", 
                                       "fighting", "water", "water", "water", "dragon", "dragon", "dragon", 
                                       "ice", "ice", "fairy"))
                     , class = c("tbl_df", "tbl", "data.frame"
                                                         )
                     , row.names = c(NA, -44L))

# create chart
pokemon%>% 
  group_by(type_1, type_2) %>% 
  summarise(n = n())%>%
  arrange(type_2)%>%
  hchart(type = "bar", hcaes(x = type_2, group = type_1, y = n))

但排列不起作用,条形图未按 type_2 排序。

如果我不在我的 hchart 中使用分组变量,它确实有效:

pokemon%>%
  group_by(#type_1, 
    type_2) %>% 
  summarise(n = n())%>%
  arrange(type_2)%>%
  hchart(type = "bar", hcaes(x = type_2#, group = type_1
                             , y = n))

有什么方法可以在使用分组变量时对我的金条进行排序吗?

我正在使用 R 3.5.2

我想我已经通过使用 highcharts() 和 hc_add_series 找到了解决方案,这确实允许安排:

pokemon <- pokemon %>% 
  group_by(type_1, type_2) %>% 
  summarise(n = n())%>%
  arrange(type_2)

# create chart
highchart() %>% 
  hc_add_series(pokemon, type = "bar", hcaes(x = type_2, group = type_1, y = n)) %>% 
  hc_xAxis(categories = pokemon$type_2)