wilkelab / ggridges

Ridgeline plots in ggplot2
https://wilkelab.org/ggridges
GNU General Public License v2.0
412 stars 31 forks source link

Enhancement: Pass additional aesthetics to quantile_fun (e.g., for weighted quantiles)? #74

Open LukasWallrich opened 2 years ago

LukasWallrich commented 2 years ago

I would like to show weighted medians in geom_density_ridges(). The most intuitive way to get there would be to pass x and weight to my quantile_fun ... but I don't think that is possible at present.

Unless I am overlooking a simpler solution, might that be a worthwhile enhancement? I could also see use cases where it would be helpful to have y within that function, for instance, to show different thresholds depending on y ...

clauswilke commented 2 years ago

There's an abandoned PR about this: #59. Feel free to pick up and finish off.

LukasWallrich commented 2 years ago

I understand that PR as wanting to add weights to the density calculation - not to the quantile lines? Would one solve the other? Then I'd certainly want to investigate.

clauswilke commented 2 years ago

Oh, sorry, I didn't read carefully enough. Those are two separate issues. It's possible already though to provide your own quantile function. Does that help?

LukasWallrich commented 2 years ago

Not cleanly - I would like to use a weighted.median(x, weight) function, but can't pass the weight in there.

As a workaround, I could probably calculate the desired outputs first and then use x just as a lookup value in my own function ... these vectors better be unique for each y value. That obviously is rather hacky ... but good enough for now. If I get to understand the ggplot2 architecture properly at some point, I will return with a PR.