Closed grantmcdermott closed 6 months ago
Should we allow free axis scaling/limits for individual facets?
This is possible to do. But it ends up requiring more work internally than I initially anticipated. Reason: We have to manually reset par("usr")
when drawing the plot elements of each individual facet at the end of tinyplot()
. If we don't reset par("usr")
, then each facet's extent is determined by the final facet plot region that was drawn higher up in the code logic. (Remember: We have to draw all of the plot regions before the drawing all the plot elements, otherwise we can't get facets to play nice with grouping.)
For posterity, I just tested a MWE with a new facet.args(... free = TRUE)
argument that adds two pieces of code logic:
if (nfacets > 1) {
# ... [existing code]
if (isTRUE(facet.args[["free"]])) {
xlim = range(split(x, facet)[[ii]])
ylim = range(split(y, facet)[[ii]])
if (!is.null(ymin)) ylim = range(ylim, range(split(ymin, facet)[[ii]]))
if (!is.null(ymax)) ylim = range(ylim, range(split(ymax, facet)[[ii]]))
frame.plot = TRUE
}
}
if (nfacets > 1) {
# ... [existing code]
if (isTRUE(facet.args[["free"]])) {
xlim = range(xx)
ylim = range(yy)
if (!is.null(yymin)) ylim = range(ylim, range(yymin))
if (!is.null(yymax)) ylim = range(ylim, range(yymax))
xlim = extendrange(range(mtcars$wt),f=0.04)
par(usr = c(extendrange(xlim), extendrange(ylim)))
}
}
This works:
pkgload::load_all("~/Documents/Projects/tinyplot")
#> ℹ Loading tinyplot
tpar(facet.bg = "grey90")
plt(
mpg ~ wt, mtcars,
facet = cyl ~ am,
facet.args = list(free = TRUE), ## TEST
main = "Free facet axes scales/limits (example)"
)
Created on 2024-03-09 with reprex v2.1.0
Buuut.... it seems fragile: I really don't like messing with par("usr")
manually and I'm not sure that it's worth the effort. So, I'm marking as free axis scales as "wont support" for the moment. We can revisit if there's strong user demand for it.
Moved from #83.
y ~ x | by | facetrow ~ facetcol
? Decision: No.y ~ x | by, facet = TRUE
could treatby
as a facet variable and override the default grouping behaivour (distinct fromfacet = "by"
, which treats them as equivalent). Decision: No.cex
be adjusted to match the smaller facet elements (or, vice versa)? (#91)Relevant comments:
https://github.com/grantmcdermott/plot2/pull/83#issuecomment-1834663508 (@zeileis)
https://github.com/grantmcdermott/plot2/pull/83#issuecomment-1838775014 (@vincentarelbundock)