Skip to content

Conversation

@zeileis
Copy link
Collaborator

@zeileis zeileis commented Dec 15, 2025

Fixes #534

With this PR tinyplot allows formulas without x variable, e.g., as in ~ 1 or ~ 0 or y ~ 1 or y ~ 0 etc. All of these are translated to x = NULL in the default method call.

df <- data.frame(x0 = c(0, .1), y0 = c(.2,1), x1 = c(1, .9), y1 = c(.75, 0))
tinyplot(~ 0, xmin=x0, ymin=y0, xmax=x1, ymax=y1, data = df, type = "segments")
tinyplot-nullformula

Note that the axis labels are not ideal, though. I wasn't sure where this would best be sanitized.

@zeileis
Copy link
Collaborator Author

zeileis commented Dec 15, 2025

When checking how the type would be handled for x = NULL, I noticed that the type sanitizer currently only handles bivariate y ~ x plots:

https://github.com/grantmcdermott/tinyplot/blob/main/R/sanitize_type.R#L45-L55

I would recommend that we add support for the following:

  • x = <factor>, y = NULL: barplot
  • x = NULL, y = <factor>: barplot
  • x = NULL, y = !<factor>: scatterplot against index
  • x = !<factor>, y = NULL: histogram

Note, however, that the latter two are not consistent with the base R plot() function. But maybe that's ok, given that base R's formula and default method are not even consistent here. For plot(~ x) a stripchart() is generated (which I find far less useful than a histogram) and for plot(x) a scatterplot against the index is generated.

@grantmcdermott
Copy link
Owner

Note, however, that the latter two are not consistent with the base R plot() function. But maybe that's ok, given that base R's formula and default method are not even consistent here.

Thanks @zeileis and I agree. We should follow base plot conventions where possible, but be fine to deviate in cases like this where it makes sense. Do you want to tackle these univariate cases in this PR, or a separate one?

Everything else looks good, except the axis label as you say. I'd need to play around with the code a bit to see the best place to fix.

@zeileis
Copy link
Collaborator Author

zeileis commented Dec 20, 2025

Thanks for the feedback! I think it makes sense to include the univariate defaults in this PR because we can think about which formulas map to which x/y specifications which in turn map to plot types. I'll try to post a suggestion later today...

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.

Clean way to enter formula method for types that don't require x (rect, segments)

3 participants