tinyplot icon indicating copy to clipboard operation
tinyplot copied to clipboard

Support manual breaks (`x/yaxb`)

Open grantmcdermott opened this issue 7 months ago • 4 comments

Closes #366

Operationalised through the new xaxb and yaxb args. Should play nicely with axis limits and the panel grid, as well as any formatting adjustments applied through x/yaxl.

pkgload::load_all("~/Documents/Projects/tinyplot")
#> ℹ Loading tinyplot

plt(
  mpg ~ hp | am, mtcars, facet = "by",
  xaxb = c(80, 160, 240, 320),
  yaxb = c(12, 16, 24, 40),
  grid = TRUE
)


plt(
  count ~ spray,
  data = InsectSprays,
  xaxb = c("A", "C", "F"), xaxl = tolower, 
  yaxb = c(10, 30), yaxl = "$"
)

Created on 2025-05-17 with reprex v2.1.1

grantmcdermott avatar May 18 '25 05:05 grantmcdermott

@vincentarelbundock I think that this covers the use case/need that you had in mind. Would you mind reviewing or taking a quick look when you get a chance?

grantmcdermott avatar May 18 '25 05:05 grantmcdermott

Thanks, this is exactly what I needed. A really important feature! (sorry I didn't get to it in time).

The only comment I have is about whether we should give xaxb or xlim priority when both are specified and enter in conflict. My gut says that xlim should have priority since it is a base setting, but I don't feel super strongly about it.

Rest looks great.

vincentarelbundock avatar May 18 '25 10:05 vincentarelbundock

Nice! We also need to incorporate that into type_spineplot(). The xaxb would be the default for breaks unless the latter is specified by the user. The yaxb should be taken to indicate which of the y-axis categories should be labeled or not.

zeileis avatar May 18 '25 11:05 zeileis

Nice! We also need to incorporate that into type_spineplot(). The xaxb would be the default for breaks unless the latter is specified by the user. The yaxb should be taken to indicate which of the y-axis categories should be labeled or not.

Good catch. So, internally we would just need to make sure that (say) xaxb is transferred to breaks.

~Question, though: Should we hide these type_spineplot()-specific arguments from the user then and rather enforce that they go through the top-level x/yaxb arguments for consistency? I know it would be a breaking change, but I think we should favour a single (common) top-level approach for doing something if possible. Alternatively, if we keep them, which takes precedence if the user specifies both (say) xaxb and type_spineplot(breaks = ...)?~ (Edit: Ignore and see below.)

grantmcdermott avatar May 18 '25 20:05 grantmcdermott

Question, though: Should we hide these type_spineplot()-specific arguments from the user then and rather enforce that they go through the top-level x/yaxb arguments for consistency? I know it would be a breaking change, but I think we should favour a single (common) top-level approach for doing something if possible. Alternatively, if we keep them, which takes precedence if the user specifies both (say) xaxb and type_spineplot(breaks = ...)?

Sorry, ignore what I was saying above. I was quickly typing on my phone while I was out and hadn't read your comments properly or thought about it clearly. I now recall that type_spineplot(breaks = ...) accepts a single number (analogous to histograms), whereas xaxb specifies the exact break points. As such, I agree with your comment @zeileis that "xaxb would be the default for breaks unless the latter is specified by the user."

grantmcdermott avatar May 19 '25 01:05 grantmcdermott

Like in hist(), the breaks can be both, either the number of breaks or the location of the breaks. So if xaxb is specified and breaks is not (i.e., NULL), breaks = xaxb can be used.

zeileis avatar May 19 '25 01:05 zeileis

Okay, I think we're good to go. Thanks both for the comments and suggestions ;-)

grantmcdermott avatar May 19 '25 04:05 grantmcdermott

Thanks!

zeileis avatar May 19 '25 06:05 zeileis