From f76909592f27504b04dcbe6037298cd9fe58af70 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Tue, 16 Sep 2025 16:38:42 -0700 Subject: [PATCH 1/3] Use pass full tpar list to draw_face_window - tweak get_tpar() while we're at it --- R/facet.R | 33 +++++++++++++++++---------------- R/tinyplot.R | 4 ++-- R/tpar.R | 5 +++-- R/zzz.R | 2 +- man/facet.Rd | 2 +- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/R/facet.R b/R/facet.R index 861853e2..68e36863 100644 --- a/R/facet.R +++ b/R/facet.R @@ -34,9 +34,11 @@ draw_facet_window = function( type, x, xmax, xmin, y, ymax, ymin, - dynmar = NULL + tpars = NULL ) { + if (is.null(tpars)) tpars = tpar() + # if add is TRUE, just return inputs without any calculations if (isTRUE(add)) { return(as.list(environment())) @@ -47,15 +49,14 @@ draw_facet_window = function( if (!is.null(yaxb) && !is.null(ylabs)) ylabs = yaxb # draw background color only in the grid rectangle - grid.bg = get_tpar("grid.bg") + grid.bg = get_tpar("grid.bg", tpar_list = tpars) if (!is.null(grid.bg)) { corners = par("usr") rect(corners[1], corners[3], corners[2], corners[4], col = grid.bg, border = NA) } ## dynamic margins flag - if (is.null(dynmar)) dynmar = get_tpar("dynmar") - dynmar = isTRUE(dynmar) + dynmar = isTRUE(get_tpar("dynmar", tpar_list = tpars)) ## optionally allow to modify the style of axis interval calculation if (!is.null(xaxs)) par(xaxs = xaxs) @@ -263,17 +264,17 @@ draw_facet_window = function( side = xside, type = xaxt, labeller = xaxl, - cex = get_tpar(c("cex.xaxs", "cex.axis"), 0.8), - lwd = get_tpar(c("lwd.xaxs", "lwd.axis"), 1), - lty = get_tpar(c("lty.xaxs", "lty.axis"), 1) + cex = get_tpar(c("cex.xaxs", "cex.axis"), 0.8, tpar_list = tpars), + lwd = get_tpar(c("lwd.xaxs", "lwd.axis"), 1, tpar_list = tpars), + lty = get_tpar(c("lty.xaxs", "lty.axis"), 1, tpar_list = tpars) ) args_y = list(y, side = yside, type = yaxt, labeller = yaxl, - cex = get_tpar(c("cex.yaxs", "cex.axis"), 0.8), - lwd = get_tpar(c("lwd.yaxs", "lwd.axis"), 1), - lty = get_tpar(c("lty.yaxs", "lty.axis"), 1) + cex = get_tpar(c("cex.yaxs", "cex.axis"), 0.8, tpar_list = tpars), + lwd = get_tpar(c("lwd.yaxs", "lwd.axis"), 1, tpar_list = tpars), + lty = get_tpar(c("lty.yaxs", "lty.axis"), 1, tpar_list = tpars) ) if (!is.null(xaxb)) args_x$at = xaxb if (!is.null(yaxb)) args_y$at = yaxb @@ -475,7 +476,7 @@ draw_facet_window = function( if (frame.plot) box() # panel grid lines - if (is.null(grid)) grid = .tpar[["grid"]] + if (is.null(grid)) grid = get_tpar("grid", tpar_list = tpars) if (!is.null(grid)) { if (is.logical(grid)) { ## If grid is TRUE create a default grid. Rather than just calling the default grid() @@ -485,22 +486,22 @@ draw_facet_window = function( if (isTRUE(grid)) { gnx = gny = NULL if (!is.null(xaxb)) { - abline(v = xaxb, col = .tpar[["grid.col"]], lty = .tpar[["grid.lty"]], lwd = .tpar[["grid.lwd"]]) + abline(v = xaxb, col = get_tpar("grid.col", tpar_list = tpars), lty = get_tpar("grid.lty", tpar_list = tpars), lwd = get_tpar("grid.lwd", tpar_list = tpars)) gnx = NA } else if (!any(c(par("xlog"), type == "boxplot"))) { xg = if (!inherits(x, c("POSIXt", "Date"))) axTicks(side = 1) else axTicksDateTime(side = 1, x = x) - abline(v = xg, col = .tpar[["grid.col"]], lty = .tpar[["grid.lty"]], lwd = .tpar[["grid.lwd"]]) + abline(v = xg, col = get_tpar("grid.col", tpar_list = tpars), lty = get_tpar("grid.lty", tpar_list = tpars), lwd = get_tpar("grid.lwd", tpar_list = tpars)) gnx = NA } if (!is.null(yaxb)) { - abline(h = yaxb, col = .tpar[["grid.col"]], lty = .tpar[["grid.lty"]], lwd = .tpar[["grid.lwd"]]) + abline(h = yaxb, col = get_tpar("grid.col", tpar_list = tpars), lty = get_tpar("grid.lty", tpar_list = tpars), lwd = get_tpar("grid.lwd", tpar_list = tpars)) gny = NA } else if (!any(c(par("ylog"), type == "boxplot"))) { yg = if (!inherits(y, c("POSIXt", "Date"))) axTicks(side = 2) else axTicksDateTime(side = 2, x = x) - abline(h = yg, col = .tpar[["grid.col"]], lty = .tpar[["grid.lty"]], lwd = .tpar[["grid.lwd"]]) + abline(h = yg, col = get_tpar("grid.col", tpar_list = tpars), lty = get_tpar("grid.lty", tpar_list = tpars), lwd = get_tpar("grid.lwd", tpar_list = tpars)) gny = NA } - grid(nx = gnx, ny = gny, col = .tpar[["grid.col"]], lty = .tpar[["grid.lty"]], lwd = .tpar[["grid.lwd"]]) + grid(nx = gnx, ny = gny, col = get_tpar("grid.col", tpar_list = tpars), lty = get_tpar("grid.lty", tpar_list = tpars), lwd = get_tpar("grid.lwd", tpar_list = tpars)) } } else { grid diff --git a/R/tinyplot.R b/R/tinyplot.R index 522fb5d6..a6fbf35e 100644 --- a/R/tinyplot.R +++ b/R/tinyplot.R @@ -1230,7 +1230,7 @@ tinyplot.default = function( type = type, x = x, xmax = xmax, xmin = xmin, y = y, ymax = ymax, ymin = ymin, - dynmar = dynmar + tpars = tpars ), list = list( add = add, @@ -1254,7 +1254,7 @@ tinyplot.default = function( type = type, x = datapoints$x, xmax = datapoints$xmax, xmin = datapoints$xmin, y = datapoints$y, ymax = datapoints$ymax, ymin = datapoints$ymin, - dynmar = get_tpar("dynmar") # https://github.com/grantmcdermott/tinyplot/issues/474 + tpars = tpar() # https://github.com/grantmcdermott/tinyplot/issues/474 ), getNamespace("tinyplot") ) diff --git a/R/tpar.R b/R/tpar.R index 4aa59794..763b6374 100644 --- a/R/tpar.R +++ b/R/tpar.R @@ -197,11 +197,12 @@ tpar = function(..., hook = FALSE) { # Two levels of priority: .tpar[["name"]] -> par("name") -get_tpar = function(opts, default = NULL) { +get_tpar = function(opts, default = NULL, tpar_list = NULL) { + if (is.null(tpar_list)) tpar_list = .tpar # parameter priority # .tpar[["name"]] -> par("name") for (o in opts) { - tp = .tpar[[o]] + tp = tpar_list[[o]] if (!is.null(tp)) { return(tp) } else { diff --git a/R/zzz.R b/R/zzz.R index 942e7082..0274023e 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -18,7 +18,6 @@ "cex_fct_adj", "dots", "draw", - "dynmar", "facet_bg", "facet_border", "facet_col", @@ -43,6 +42,7 @@ "oyaxis", "ribbon.alpha", "split_data", + "tpars", "type", "x", "xaxl", diff --git a/man/facet.Rd b/man/facet.Rd index 4ee9002e..5e0bd34d 100644 --- a/man/facet.Rd +++ b/man/facet.Rd @@ -54,7 +54,7 @@ draw_facet_window( y, ymax, ymin, - dynmar = NULL + tpars = NULL ) facet_layout(facet, add = FALSE, facet.args = list()) From 316ad4782e7e9e6ecb25cb056ffb1b2c93e60b34 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Tue, 16 Sep 2025 17:01:01 -0700 Subject: [PATCH 2/3] tweak tinytheme showcase example --- R/tinytheme.R | 6 ++++-- man/tinytheme.Rd | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/R/tinytheme.R b/R/tinytheme.R index ab1e9f12..0eddd4da 100644 --- a/R/tinytheme.R +++ b/R/tinytheme.R @@ -96,9 +96,11 @@ #' tinytheme(thm) #' tinyplot( #' I(Sepal.Length*1e4) ~ Petal.Length | Species, facet = "by", data = iris, -#' main = "Demonstration of tinyplot themes", -#' sub = paste0('tinytheme("', thm, '")') +#' yaxl = ",", +#' main = paste0('tinytheme("', thm, '")'), +#' sub = "A subtitle" #' ) +#' box("outer", lty = 2) #' } #' #' # Reset diff --git a/man/tinytheme.Rd b/man/tinytheme.Rd index 2411c946..3508a1f7 100644 --- a/man/tinytheme.Rd +++ b/man/tinytheme.Rd @@ -108,9 +108,11 @@ for (thm in thms) { tinytheme(thm) tinyplot( I(Sepal.Length*1e4) ~ Petal.Length | Species, facet = "by", data = iris, - main = "Demonstration of tinyplot themes", - sub = paste0('tinytheme("', thm, '")') + yaxl = ",", + main = paste0('tinytheme("', thm, '")'), + sub = "A subtitle" ) + box("outer", lty = 2) } # Reset From 6d9d91ca05b485c8d8f2f174cfe3e898cdca68af Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Tue, 16 Sep 2025 17:03:29 -0700 Subject: [PATCH 3/3] news --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index bd9b7710..aecaa3af 100644 --- a/NEWS.md +++ b/NEWS.md @@ -41,7 +41,7 @@ where the formatting is also better._ - `type_text()` can now also deal with factor `x`/`y` variables by converting them to numeric which helps to add text to barplots etc. (#470 @zeileis) - Fix bug where sourced (non-interactive) scripts with `tinytheme()` calls were - not inheriting the correct LHS margin spacing. (#475 @grantmcdermott) + not inheriting the correct parameters and spacing. (#475, #481 @grantmcdermott) ### Internals