Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grouped box plot with multiple variables #409

Open
guybrettrobertson opened this issue Feb 25, 2022 · 8 comments
Open

Grouped box plot with multiple variables #409

guybrettrobertson opened this issue Feb 25, 2022 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@guybrettrobertson
Copy link

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
Copy link
Author

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
Copy link

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
Copy link
Owner

#253

@munoztd0
Copy link
Collaborator

munoztd0 commented Aug 3, 2022

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

#253 (comment)

@munoztd0 munoztd0 self-assigned this Jun 12, 2023
@munoztd0 munoztd0 added the enhancement New feature or request label Jun 12, 2023
@munoztd0 munoztd0 pinned this issue Jun 12, 2023
@sharp-lilac
Copy link

Hi, any news on this? Boxplots are so important for data visualizations and not being able to group by multiple variables is really surprising. Any workarounds?

@munoztd0
Copy link
Collaborator

@sharp-lilac I agree with you is just that boxplots are not "normal" plots they are constituted of various diverse source of information (aggregated statistics as well a raw data points, i.e. outliers.)

I started devloping a new branch that will implement a new approach for boxplots but it might get ugly at first, the commit 06c2e5d shows the first steps.

On the branch grouped_boxplot:

library(echarts4r)

data <- data.frame(
  category = rep(LETTERS[1:5], each = 100),
  value = rnorm(500, mean = rep(1:5, each = 100), sd = 1:5),
  gender = sample(c("M", "F"), 500, replace = TRUE)
)

plot <- data |>
  group_by(gender) |>
  e_charts(category) |>
  e_boxplot_group_(serie = "value") |>
  e_x_axis(name = "Category") |>
  e_y_axis(name = "Value") |>
  e_tooltip(trigger = "axis") |>
  e_legend(show = TRUE)

plot

image

Created on 2024-11-25 with reprex v2.0.2

@munoztd0
Copy link
Collaborator

Hey, glad it kinda works.
Yeah I know, I haven't finished implementing the outliers. I have to refactor it somehow, work in progress.

@sharp-lilac
Copy link

@munoztd0 Thank you! Exciting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

5 participants