Skip to content

handle boxplot without y-variable in tinyplot.default#454

Merged
grantmcdermott merged 2 commits intomainfrom
boxplot-nogroups
Aug 14, 2025
Merged

handle boxplot without y-variable in tinyplot.default#454
grantmcdermott merged 2 commits intomainfrom
boxplot-nogroups

Conversation

@zeileis
Copy link
Copy Markdown
Collaborator

@zeileis zeileis commented Aug 12, 2025

Fixes #453

Like boxplot(x) it would be good if tinyplot(x, type = "boxplot") created a single boxplot without a grouping variable (and without corresponding labels on the x-axis).

I think that this is not easy to handle in type_boxplot() but requires a few simple workarounds in tinyplot.default() where the is.null(y) cases are handled. I've added:

    } else if (type == "boxplot") {
      y = x
      x = rep.int("", length(y))
      xlab = ""
      xaxt = "a"

With this both the default and the formula interface work:

tinyplot(Nile, type = "boxplot")
tinyplot(~ Nile, type = "boxplot")
tinyplot-boxplot

Grouping and faceting still works:

tinyplot(~ bill_len | species, data = penguins, type = "boxplot")
tinyplot-boxplot
tinyplot(~ bill_len, facet = ~ species, data = penguins, type = "boxplot")
tinyplot-boxplot

@zeileis
Copy link
Copy Markdown
Collaborator Author

zeileis commented Aug 12, 2025

P.S.: It would be good to modularize this variable handling in the type_* functions somehow.

P.P.S.: While looking at data_boxplot() I noticed that ymin and ymax are set up but apparently never used. I think this could just be dropped?

https://github.com/grantmcdermott/tinyplot/blob/boxplot-nogroups/R/type_boxplot.R#L131-L132

@grantmcdermott
Copy link
Copy Markdown
Owner

Great, thanks for simple workaround @zeileis.

P.S.: It would be good to modularize this variable handling in the type_* functions somehow.

Agree. I worry it will require a larger refactoring b/c these exceptions come before the type-based datapoints construction. OTOH the current logic might just be inertia from the original design. In which case, moving to a modularized approach would kill two birds with one stone by nicely simplifying things.

P.P.S.: While looking at data_boxplot() I noticed that ymin and ymax are set up but apparently never used. I think this could just be dropped?

I might be mis-remembering (we should test), but I think we need those for the flip logic here. I have a vague memory of that anyway...

@grantmcdermott
Copy link
Copy Markdown
Owner

@zeileis Assuming you agree with my comments (which basically amount to "let's tackle these other issues separately"), do you mind adding a NEWS item? We can merge directly afterwards.

@zeileis
Copy link
Copy Markdown
Collaborator Author

zeileis commented Aug 14, 2025

OK, good, NEWS item added now.

@grantmcdermott grantmcdermott merged commit dd121a1 into main Aug 14, 2025
3 checks passed
@grantmcdermott grantmcdermott deleted the boxplot-nogroups branch August 14, 2025 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Boxplot from one variable

2 participants