tinyplot icon indicating copy to clipboard operation
tinyplot copied to clipboard

Ridgeline plot

Open etiennebacher opened this issue 2 years ago • 4 comments

Hi @grantmcdermott, I was looking for how to make ridgeline plots in base R and I came across this package that has a single function to do it: https://github.com/R-CoderDotCom/ridgeline

It is MIT licensed so it should be fine to take the code. I'm not making a PR for this because I don't know what kind of implementation you'd prefer (formula, arguments, etc.) and because the code of the plot2.* functions is quite dense. I'm just putting this here so that you or someone else don't have to start from scratch if you choose/have time to implement this.

etiennebacher avatar Aug 22 '23 09:08 etiennebacher

Nice, thanks. (That @karoliskoncevicius tutorial is fantastic btw. If/when I integrate ridgelines into plot2, I'll be sure to give him credit.)

the code of the plot2.* functions is quite dense

I know, it's becoming a bit unwieldy. I'm not a fan of monolithic function scripts, but some of that is unavoidable here to handle the correct passing between methods and plot types. I do want to try and pull out the legend drawing section into a separate, non-exported function at some point, though.

grantmcdermott avatar Aug 22 '23 19:08 grantmcdermott

PS. I know it's not a ridgeline plot, but in the latest dev version you can at least do things like:

library(plot2)

plot2(~ weight | feed, chickwts, type = "density", bg = "by", col = "white", palette = "Zissou 1")

Created on 2023-08-22 with reprex v2.0.2

grantmcdermott avatar Aug 22 '23 19:08 grantmcdermott

Regarding the monolithic function and separating building blocks like the legend (or drawing axes). I had made this suggestion a while back which would need some further discussions and refinements before we could implement it, I guess. Note sure whether it is still feasible given how much the code grew since April: https://github.com/grantmcdermott/plot2/issues/2#issuecomment-1510545570

zeileis avatar Aug 23 '23 07:08 zeileis

Thanks for the reminder @zeileis. I still like all of those suggestions and think we can reasonably separate out the legend drawing portion at outset (and then cycle through facets by updating par(mfg) during the group-based loop). This would at least solve your question of which component draws the legend, but we'd obviously have to test it first.

grantmcdermott avatar Aug 25 '23 02:08 grantmcdermott

Closed with #252

grantmcdermott avatar Nov 25 '24 22:11 grantmcdermott

@etiennebacher Ridgeline plots now supported via type = "ridge"/type_ridge() in the dev version. I expect the R-universe build will be ready by the time you read this.

Collectively, we ended up supporting a pretty fancy version of this FR, so I hope that you'll give it a test drive. See the examples and documentation here: https://grantmcdermott.com/tinyplot/man/type_ridge.html

grantmcdermott avatar Nov 25 '24 22:11 grantmcdermott

Hi @grantmcdermott, I lost the original usecase I had so I can't test this extensively but this looks amazing. For sure, the current implementation covers what I wanted to do (even if I don't remember the details). Nice job!

etiennebacher avatar Nov 27 '24 13:11 etiennebacher