分组条形图未分组面板压扁

Grouped barchart not group panel squashed

我正在尝试使用 highcharter 制作分组条形图,例如 here

一个可重现的例子,

library(highcharter)
library(tidyverse)
temp=structure(list(Theme = c("A1", "A1", "A1", "A1", "A1", "A1", 
"A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", "A1", 
"A1", "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", "A2", 
"A2", "A2", "A2", "A3", "A3", "A4", "A5", "A6", "A6", "A6", "A6", 
"A6", "A6", "A6", "A6", "A6", "A6", "A7", "A7", "A7", "A7", "A7", 
"A7", "A7", "A7", "A7", "A7", "A7", "A7", "A7", "A8", "A8", "A8", 
"A8", "A8", "A8", "A9", "A9", "A9", "A9", "A9", "A9", "A9", "A9", 
"A9", "A9", "A9", "A9", "A9", "A9", "A9", "A9", "A9", "A10", 
"A11", "A11", "A11", "A11", "A11", "A11", "A11", "A11", "A11", 
"A11", "A11", "A11"), Group = c("a3", "a6", "a7", "a9", "a10", 
"a11", "a22", "a27", "a30", "a42", "a52", "a56", "a63", "a66", 
"a68", "a71", "a75", "a87", "a2", "a13", "a25", "a26", "a31", 
"a39", "a49", "a51", "a67", "a72", "a73", "a86", "a94", "a60", 
"a74", "a16", "a28", "a12", "a14", "a23", "a44", "a46", "a61", 
"a62", "a69", "a70", "a79", "a1", "a18", "a34", "a41", "a48", 
"a54", "a65", "a76", "a82", "a83", "a84", "a88", "a89", "a20", 
"a35", "a40", "a50", "a77", "a78", "a4", "a8", "a21", "a29", 
"a32", "a33", "a36", "a37", "a38", "a47", "a53", "a55", "a57", 
"a58", "a59", "a85", "a91", "a81", "a5", "a15", "a17", "a19", 
"a24", "a43", "a45", "a64", "a80", "a90", "a92", "a93"), Y = c(22.4, 
-40.9, -31.9, -29.8, -10.3, -43.9, 12.9, 30.2, -69, 31.3, -31.8, 
15.4, -20.3, 7.3, -82.8, 16.4, 49.3, -8.7, 50.2, -42.9, -52.1, 
-25.3, 24.2, 47.4, 31.7, -1.2, 4.4, -4.4, -64, -73.2, -42.2, 
204.4, 45.3, -46.4, 41.5, -71.2, 3.7, -8, -40.3, 180.3, -5.9, 
101.2, -10.7, -56.8, -14.5, -42.2, -97.2, -50.5, -69.5, 65.3, 
-43.8, -16.8, -10.4, 9.8, -70.2, 26.3, -33.4, -42, 2.4, -3.9, 
37.8, -0.6, -25.9, -22.3, -2.4, -50.5, 3.9, -47.8, -37, 5.9, 
-29.9, 14.6, 150.4, 266.1, -15.1, -9.7, -26.5, 187.8, -37.5, 
-5.2, 40, -34.3, 25.8, -100, 0.1, 15.6, 29.8, -88.3, 237.9, -8.2, 
6.1, 29, -26, -9.8), col = c(FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, 
FALSE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, 
FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, 
FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE, 
FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, 
TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, 
TRUE, TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, 
FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, 
TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, 
FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, TRUE, TRUE)), .Names = c("Theme", 
"Group", "Y", "col"), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -94L))

categories_grouped=temp%>%
  group_by(Theme)%>%
  do(categories = .$Group) %>% 
  list_parse()

highchart() %>% 
  hc_xAxis(categories = categories_grouped) %>% 
  hc_add_series(data = temp, type = "bar", hcaes(y = Y,color=col),
                showInLegend = FALSE)

但是图表看起来像 特别是左边的面板都被压扁了。

有人可以指出修复方法吗? 谢谢

找到答案了。 将分组变量名称设置为 name 很重要。 也就是说,

categories_grouped=temp%>%
  group_by(name=Theme)%>%
  do(categories = .$Group) %>% 
  list_parse()

而不是

...group_by(Theme)%>%...