From 50e125995be5fe3ac0c795478565ca848666af4a Mon Sep 17 00:00:00 2001 From: Achim Zeileis Date: Wed, 4 Feb 2026 04:13:47 +0100 Subject: [PATCH 1/3] restore xaxs/yaxs when set --- R/facet.R | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/R/facet.R b/R/facet.R index 0a1a1fcb..9183a680 100644 --- a/R/facet.R +++ b/R/facet.R @@ -58,9 +58,18 @@ draw_facet_window = function( ## dynamic margins flag 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) - if (!is.null(yaxs)) par(yaxs = yaxs) + ## optionally allow to modify and restore the style of axis interval calculation + if (!is.null(xaxs) || !is.null(yaxs)) { + op = par() + if (!is.null(xaxs)) { + par(xaxs = xaxs) + on.exit(par(xaxs = op$xaxs), add = TRUE) + } + if (!is.null(yaxs)) { + par(yaxs = yaxs) + on.exit(par(yaxs = op$yaxs), add = TRUE) + } + } if (nfacets > 1) { # Set facet margins (i.e., gaps between facets) From b0cd368c98ba1be89f3079fadef65b8c69f9c4e3 Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Wed, 4 Feb 2026 06:40:57 -0500 Subject: [PATCH 2/3] issue #545 add snapshot test --- .../issue_545_xaxs_yaxs_restoration.svg | 125 ++++++++++++++++++ inst/tinytest/test-misc.R | 51 ++++--- 2 files changed, 158 insertions(+), 18 deletions(-) create mode 100644 inst/tinytest/_tinysnapshot/issue_545_xaxs_yaxs_restoration.svg diff --git a/inst/tinytest/_tinysnapshot/issue_545_xaxs_yaxs_restoration.svg b/inst/tinytest/_tinysnapshot/issue_545_xaxs_yaxs_restoration.svg new file mode 100644 index 00000000..18f12716 --- /dev/null +++ b/inst/tinytest/_tinysnapshot/issue_545_xaxs_yaxs_restoration.svg @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + +species +Count + + +Adelie +Chinstrap + + + + + + + + + +0 +20 +40 +60 +80 +100 +120 +140 + + + + + + + + + + + + + + + + + + + + + + + + +dots not cut off +Index +1:10 + + + + + + + + +2 +4 +6 +8 +10 + + + + + + +2 +4 +6 +8 +10 + + + + + + + + + + + + + + + + diff --git a/inst/tinytest/test-misc.R b/inst/tinytest/test-misc.R index 4e1317da..05e60ac5 100644 --- a/inst/tinytest/test-misc.R +++ b/inst/tinytest/test-misc.R @@ -2,15 +2,15 @@ source("helpers.R") using("tinysnapshot") # empty plot(s) -f = function () { +f = function() { tinyplot(Sepal.Length ~ Petal.Length, data = iris, type = "n") } expect_snapshot_plot(f, label = "type_n") -f = function () { +f = function() { tinyplot(Sepal.Length ~ Petal.Length | Species, data = iris, type = "n") } expect_snapshot_plot(f, label = "type_n_by") -f = function () { +f = function() { tinyplot(Sepal.Length ~ Petal.Length | Species, data = iris, type = "l", empty = TRUE) } expect_snapshot_plot(f, label = "type_l_empty") @@ -35,7 +35,7 @@ f = function() { plot(Temp ~ Day, data = airquality, log = "x") tinyplot(Temp ~ Day, data = airquality, log = "x") tpar(op) -} +} expect_snapshot_plot(f, label = "arg_log_x") f = function() { @@ -43,7 +43,7 @@ f = function() { plot(Temp ~ Day, data = airquality, log = "y") tinyplot(Temp ~ Day, data = airquality, log = "y") tpar(op) -} +} expect_snapshot_plot(f, label = "arg_log_y") f = function() { @@ -51,7 +51,7 @@ f = function() { plot(Temp ~ Day, data = airquality, log = "xy") tinyplot(Temp ~ Day, data = airquality, log = "xy") tpar(op) -} +} expect_snapshot_plot(f, label = "arg_log_xy") f = function() { @@ -59,7 +59,7 @@ f = function() { plot(Temp ~ Day, data = airquality, log = "yx") tinyplot(Temp ~ Day, data = airquality, log = "yx") tpar(op) -} +} expect_snapshot_plot(f, label = "arg_log_yx") f = function() { @@ -80,19 +80,25 @@ f = function() { expect_snapshot_plot(f, label = "addTRUE") # formatting axis tick labels -f = function() plt( - I(decrease/100) ~ treatment, data = OrchardSprays, - xaxl = tolower, yaxl = "percent" -) +f = function() { + plt( + I(decrease / 100) ~ treatment, + data = OrchardSprays, + xaxl = tolower, yaxl = "percent" + ) +} expect_snapshot_plot(f, label = "xaxl_yaxl") # formatting axis breaks and tick labels at the same time -f = function() plt( - I(decrease/100) ~ treatment, data = OrchardSprays, - xaxb = c("A", "C", "E", "G"), xaxl = tolower, - yaxb = c(0, 0.2, 0.5, 1, 1.4), yaxl = "percent", - grid = TRUE -) +f = function() { + plt( + I(decrease / 100) ~ treatment, + data = OrchardSprays, + xaxb = c("A", "C", "E", "G"), xaxl = tolower, + yaxb = c(0, 0.2, 0.5, 1, 1.4), yaxl = "percent", + grid = TRUE + ) +} expect_snapshot_plot(f, label = "xaxb_yaxb_xaxl_yaxl") @@ -101,7 +107,8 @@ if (requireNamespace("png", quietly = TRUE)) { f = function() { tmp_path = tempfile(fileext = ".png") suppressWarnings(tinyplot( - Sepal.Length ~ Petal.Length, data = iris, + Sepal.Length ~ Petal.Length, + data = iris, file = tmp_path, width = 4, height = 4 )) obj = png::readPNG(tmp_path, info = TRUE) @@ -114,3 +121,11 @@ if (requireNamespace("png", quietly = TRUE)) { expect_equal(f(), c(1200, 1200), label = "png_size") } + +# Issue #545: Restore xaxs and yaxs par settings when modified internally +f = function() { + par(mfrow = c(1, 2)) + tinyplot(~species, data = penguins, type = type_barplot()) + tinyplot(1:10, pch = 19, cex = 2, main = "dots not cut off") +} +expect_snapshot_plot(f, label = "issue_545_xaxs_yaxs_restoration") From 4ba21e10a7f2eb60e07496c9aeac758c25c23c50 Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Wed, 4 Feb 2026 06:51:47 -0500 Subject: [PATCH 3/3] news --- NEWS.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS.md b/NEWS.md index cb61f631..64c0c9ac 100644 --- a/NEWS.md +++ b/NEWS.md @@ -22,6 +22,11 @@ where the formatting is also better._ [custom types](https://grantmcdermott.com/tinyplot/vignettes/types.html#custom-types) in the `Types` vignette. (#531 @grantmcdermott) +### Bugs + +- Fixed Issue #545 where xaxs/yaxs were not restored when set by an internal function. + (#545 @zeileis) + ### Breaking changes ## v0.6.0