JohnCoene / echarts4r

🐳 ECharts 5 for R
http://echarts4r.john-coene.com/
Other
585 stars 82 forks source link

e_boxplot grouped by group1 where the x-axis listed by group2 #569

Open Patrikios opened 9 months ago

Patrikios commented 9 months ago

Image a simple data.frame with 3 columns, 2 grouping column, group1 and group2, and third value column:

df = data.frame(
  group1 = rep(c("a", "b"), 30L),
  group2 = rep(c("g1", "g2", "g3"), each = 20L),
  value = c(abs(rnorm(30)), abs(rnorm(30)) * 4)
)

I want to be able to produce comparison boxplot, where in the first case I grouped by group1 and give echarts the x axis as group2, altogether 6 box-plots comparing between members of group2 across group1

df |> 
  group_by(group1) |> # x-axis should be group1 'a' and 'b'
  e_charts(group2) |> # grouping within the group1 is 'g1', 'g2' and 'g3'
  e_boxplot(value, 
            color = rep(c("green", "orange", "red"), 2L) # colors is length of number of box-plots (2*3=6)
  )

and in the second case I grouped by group2 and give echarts the x-axis as group1, altogether 6 box-plots comparing between members of group1 (a vs b) across group1 (within g1:g3)

df |> 
  group_by(group2) |> # x-axis should be group2 'g1', 'g2' and 'g3' 
  e_charts(group1) |> # grouping within the group2 is 'a' and 'b'
  e_boxplot(value, 
            color = rep(c("#5470c6", "black"), 3L) # colors is length of number of box-plots (2*3=6)
  )

Howwever this is just my wishfull thinking, it does not work, the group_by(group1) and e_charts(group2) create x axis that consolidates the list of the values from both groups.

How can I achieve this? This is similar to https://echarts.apache.org/examples/en/editor.html?c=boxplot-multi however there is some JS applied on the data.

munoztd0 commented 9 months ago

look at #253