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

Weighted densities support #90

Merged
merged 7 commits into from
Feb 7, 2024
Merged

Conversation

joranE
Copy link
Contributor

@joranE joranE commented Feb 6, 2024

This is an attempt to resurrect PR59 from @mkoohafkan.

I tried to address the notes on the original PR, narrowing the focus to just adding the weight aesthetic and adding two tests, one for the unweighted density case and one for the weighted case.

gg_no_wts <- layer_data(ggplot(df, aes(x = x, y = 0)) + stat_density_ridges())
d_no_wts <- stats::density(df$x)

expect_equal(gg_no_wts$density,d_no_wts$y)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please always put a space after a comma (there are a few more cases like that in the following lines).

@clauswilke
Copy link
Collaborator

This generally looks good to me. Could you also make an entry in NEWS.md? See ggridges version 0.5.5 for examples by external contributors.

@joranE
Copy link
Contributor Author

joranE commented Feb 6, 2024

Thanks for the quick turnaround! Let me know if there's anything else I need to clean up!

@clauswilke clauswilke merged commit a8a9982 into wilkelab:master Feb 7, 2024
5 checks passed
@clauswilke
Copy link
Collaborator

Thanks for your contribution! I just recently made a release, so not sure how quickly this will percolate to CRAN. But at least it's in the github version now.

This was referenced Feb 7, 2024
@noahhaber
Copy link

noahhaber commented Jan 15, 2025

Did this ever get deployed on CRAN? I am not seeing this functionality in the CRAN version, which was uploaded in Jan 2024 (before this commit) https://cran.r-project.org/web/packages/ggridges/index.html

Edit:

When I try to run the test code:

`df <- data.frame(x = rnorm(100),wts = runif(100))
df$wts <- df$wts / sum(df$wts)

gg_wts <- layer_data(ggplot(df, aes(x = x, y = 0, weight = wts)) + stat_density_ridges())`

I get the following:
Picking joint bandwidth of 0.413 Warning message: The following aesthetics were dropped during statistical transformation: weight. ℹ This can happen when ggplot fails to infer the correct grouping structure in the data. ℹ Did you forget to specify a groupaesthetic or to convert a numerical variable into a factor?

I have not been able to get the weighting to work properly

@clauswilke
Copy link
Collaborator

No, it's not yet on CRAN, sorry. I need to prepare a new release. Haven't gotten around to that yet.

If there is a warning message about dropped aesthetics that means ggridges needs to explicitly declare those aesthetics as ones that will be dropped. Beyond that, the warning message should not affect the output.

Can you test with the ggridges development version whether weights work as they should? (By testing whether visually the plot changes. Again, the warning can be ignored and needs to be fixed.)

@noahhaber
Copy link

noahhaber commented Jan 15, 2025 via email

@clauswilke
Copy link
Collaborator

That seems strange, because now looking at the code it does correctly declare that weight is a dropped aesthetic and we also added a test for weighted and unweighted plots so things don't quite add up for me.

@noahhaber
Copy link

noahhaber commented Jan 15, 2025 via email

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

Successfully merging this pull request may close these issues.

3 participants