tinyplot
tinyplot copied to clipboard
Ridgeline plot
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.
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.
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
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
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.
Closed with #252
@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
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!