grantmcdermott / tinyplot

Lightweight extension of the base R graphics system
https://grantmcdermott.com/tinyplot
Apache License 2.0
208 stars 7 forks source link

Ridgeline plot #71

Open etiennebacher opened 10 months ago

etiennebacher commented 10 months ago

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.

grantmcdermott commented 10 months ago

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 commented 10 months ago

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

zeileis commented 10 months ago

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

grantmcdermott commented 10 months ago

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.