JohnCoene / echarts4r

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

Grouped box plot with multiple variables #409

Open guybrettrobertson opened 2 years ago

guybrettrobertson commented 2 years ago

Is there a way to create a grouped box plot with multiple grouping variables using {echarts4r}?

I would like to create a grouped box plot with multiple variables comparable to this {ggplot2} plot: https://www.r-graph-gallery.com/265-grouped-boxplot-with-ggplot2.html unnamed-chunk-1-1

I have tried the following:

variety = rep(LETTERS[1:7], each=40)
treatment = rep(c("high","low"),each=20)
note = seq(1:280)+sample(1:150, 280, replace=T)

data.frame(variety, treatment ,  note) |>
  echarts4r::group_by(variety, treatment) |>
  echarts4r::e_charts() |>
  echarts4r::e_boxplot(note) |>
  echarts4r::e_legend()

But it gives me this: Rplot

I have also tried using e_add_nested but it doesn't seem to work for boxplots.

guybrettrobertson commented 2 years ago

I just noticed that has already come up in issue 253 but no clean solution was available at the time. Have any developments been made on this?

sandra-ab commented 2 years ago

I would love this feature too. I've been using bar charts as a workaround (where the multiple grouping works as expected), but often boxplots are just so much more appropriate. :)

JohnCoene commented 2 years ago

253

munoztd0 commented 2 years ago

Created a gist function to do it -> https://gist.github.com/munoztd0/c860717d1f29e8a1b9114c46e945202e

https://github.com/JohnCoene/echarts4r/issues/253#issuecomment-1204012312