njudd / ggrain

{package} Make beautiful Raincloud plots in R!
Other
67 stars 4 forks source link

Using 'f' option without explicit arg.pos arguments causes error #1

Closed cjungerius closed 1 year ago

cjungerius commented 1 year ago

Hi there! I've been enjoying trying out your package to display some data for an article I'm writing. I have run into one slight issue though: when plotting some paired data points with the rain.side = 'f' condition will always trigger the warning about supplying explicit position instructions to the violin and boxplot components and default to 2 group 2 timepoint positions. This is easily fixed (after some trial and error about appropriate nudge sizes), and perhaps intended behaviour - However, after studying your vignette, it seems like at least at some point in development, it was possible to call the rain.side = 'f' argument without providing explicit positions for very simple designs (e.g. a 1 group, 2 timepoint design). Could you confirm whether this is intended behaviour or a bug?

As for the source of this 'bug', it seems like the if/else statement in lines 136-138 of geom_rain.R will always trigger when rain.side is set to 'f', because the default argumentsto violin.args.pos includes a side argument (setting it to 'r'). Again, this might be intended, to make the user explicitly state the positioning, but it seemed at odds with the vignette behaviour.

njudd commented 1 year ago

Thanks for pointing this out, it is less than ideal - when writing a response I thought of a solution to this issue:

I added arguments 'f1x1' and 'f2x2' for rain.side. This allows a user to use them to get good nudging defaults for 1-by-1 and 2-by-2 flanking rainclouds - which should be 95% of flanking use cases. This solves the endless warning for users, yet allows more advanced users (e.g., 4by4 flanking) to specify their own nudging values (which won't trigger the warning; as they won't specify a side argument in violin.args.pos) and informs the novice user. I added a note in the warning about 'f1x1' and 'f2x2' options.

Minimal repro:

library(ggplot2)
ggplot(iris[iris$Species %in% c('setosa', 'versicolor'),], aes(Species, Sepal.Length)) +
  ggrain::geom_rain(rain.side = "f1x1")

As you discovered, this issue stems from flanking rainclouds needing a vector of nudging values per group and time (negative for left elements and positive values for right). This issue isn't present for left and right rainclouds, they can be repeated endlessly as the single nudging value is just replicated.

will update the vingette soon

p.s. I sit in the Jasp office in UvA on (most) Fridays, I saw you're in the same lab as Lynn swing by if you have any other suggestions to make the function easier to use!

cjungerius commented 1 year ago

I realise now I never followed up on this - Thanks for the update! The new options, in combination with me understanding the functions a bit better, helped a lot, and now I have some figures that are going to (hopefully) appear in my next paper. So thanks again for all your hard work on this toolbox!

I'm unfortunately stationed at the VU, so I'm a bit further away than my lab position suggests, but if I ever have some ideas and find myself in the neighbourhood I'll be sure to swing by.