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

Add 'by' argument to plot_histogram and plot_density #181

Open
seb-mueller opened this issue Apr 3, 2024 · 3 comments
Open

Add 'by' argument to plot_histogram and plot_density #181

seb-mueller opened this issue Apr 3, 2024 · 3 comments
Assignees
Labels
type: enhancement Improvement on an existing feature
Milestone

Comments

@seb-mueller
Copy link

Similar to #139, it would be great to have the by argument for those functions.
This would be in particular useful for multimodal data for which boxplots are limited.

@boxuancui
Copy link
Owner

Hi @seb-mueller, thanks for your suggestion, but I am a little confused with the request. Histogram is basically a univariate frequency counter, and I don't see how that changes for multimodal data. With that, I don't see how a by argument can apply here. Would you mind creating an example to further illustrate your idea? Thanks!

@seb-mueller
Copy link
Author

Thanks for getting back, maybe let's use the inbuild mpg dataset as example.
Say I want to compare the distribution for all covariates but for each fl.
Naively, I'd do something like plot_density(mpg, by = "fl")
I've copied some native ggplot code to make the case for just the cty covariate, but
I'd like to get the same for all covariates (colored or split up by "fl"):

library(ggplot2)
library(DataExplorer)
plot_density(mpg, ncol = 2L)

ggplot(mpg, aes(x = cty, fill = fl)) +
geom_density()
#> Warning: Groups with fewer than two data points have been dropped.
#> Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
#> -Inf

ggplot(mpg, aes(x = cty, color = fl)) +
geom_density()
#> Warning: Groups with fewer than two data points have been dropped.
#> no non-missing arguments to max; returning -Inf

Created on 2024-04-03 with reprex v2.1.0

@boxuancui
Copy link
Owner

Thanks for the detailed explanation. That makes a lot of sense now.

@boxuancui boxuancui self-assigned this Apr 3, 2024
@boxuancui boxuancui added the type: enhancement Improvement on an existing feature label Apr 3, 2024
@boxuancui boxuancui added this to the v0.9.0 milestone Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Improvement on an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants