From 0c1c05483d7eea6b2aabda388918f4848e754c92 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Wed, 25 Mar 2026 21:32:03 -0700 Subject: [PATCH 1/4] default theme margin gotcha --- R/tinyplot.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/R/tinyplot.R b/R/tinyplot.R index 2ba8f847..f254d3a7 100644 --- a/R/tinyplot.R +++ b/R/tinyplot.R @@ -692,6 +692,12 @@ tinyplot.default = function( } else { warning('Argument `theme` must be a character of length 1 (e.g. "clean"), or a list. Ignoring.') } + # Reset mar to pre-theme value so legend margin adjustment isn't + # clobbered. Only needed for "default" theme which uses hook = FALSE + # and thus sets par(mar) immediately. (#557) + if (is.character(theme) && theme == "default") { + par(mar = opar$mar) + } dtheme = theme_default otheme = opar[names(dtheme)] From a6e62f26f573f3cc4b4421e4f9a052e5042bb03c Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Wed, 25 Mar 2026 21:34:09 -0700 Subject: [PATCH 2/4] news --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index a6d67cba..9c2315ae 100644 --- a/NEWS.md +++ b/NEWS.md @@ -34,6 +34,10 @@ where the formatting is also better._ - Fixed `type_ridge()` fill errors for themes that set a qualitative palette, e.g. `"clean2"`. (#564 @grantmcdermott) +- Fixed plot clipping when using ephemeral `theme = "default"` with a legend + and `tinyplot_add()`. Thanks to @katrinabrock for the report in #557. + (#565 @grantmcdermott) + ### Internals - We now encourage type-specific legend customizations within the individual From 813a60cfe535b67922054620b3e741dbbccec756 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Thu, 26 Mar 2026 12:35:24 -0700 Subject: [PATCH 3/4] better fix --- R/tinyplot.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/R/tinyplot.R b/R/tinyplot.R index f254d3a7..3a980165 100644 --- a/R/tinyplot.R +++ b/R/tinyplot.R @@ -692,19 +692,19 @@ tinyplot.default = function( } else { warning('Argument `theme` must be a character of length 1 (e.g. "clean"), or a list. Ignoring.') } - # Reset mar to pre-theme value so legend margin adjustment isn't - # clobbered. Only needed for "default" theme which uses hook = FALSE - # and thus sets par(mar) immediately. (#557) if (is.character(theme) && theme == "default") { + # Reset mar to pre-theme value so legend margin adjustment isn't + # clobbered. Only needed for "default" theme which uses hook = FALSE + # and thus sets par(mar) immediately. (#557) par(mar = opar$mar) + on.exit(init_tpar(rm_hook = TRUE), add = TRUE) + } else { + dtheme = theme_default + otheme = opar[names(dtheme)] + on.exit(do.call(tinytheme, otheme), add = TRUE) } - dtheme = theme_default - otheme = opar[names(dtheme)] - - on.exit(do.call(tinytheme, otheme), add = TRUE) } - # ## settings container ----- # From 46e4055cec54637997099bde84d2689bee9ee0b9 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Thu, 26 Mar 2026 12:35:32 -0700 Subject: [PATCH 4/4] test --- .../ephemeral_default_theme_add.svg | 80 +++++++++++++++++++ inst/tinytest/test-tinytheme.R | 9 ++- 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 inst/tinytest/_tinysnapshot/ephemeral_default_theme_add.svg diff --git a/inst/tinytest/_tinysnapshot/ephemeral_default_theme_add.svg b/inst/tinytest/_tinysnapshot/ephemeral_default_theme_add.svg new file mode 100644 index 00000000..cbc30034 --- /dev/null +++ b/inst/tinytest/_tinysnapshot/ephemeral_default_theme_add.svg @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + +c("a", "a", "a") +c(1, 1, 1) + + + + + + + +1:3 +c(1, 1, 1) + + + + + + + + +1.0 +1.5 +2.0 +2.5 +3.0 + + + + + + +0.6 +0.8 +1.0 +1.2 +1.4 + + + + + + + + + + + + + + + + diff --git a/inst/tinytest/test-tinytheme.R b/inst/tinytest/test-tinytheme.R index 01bb9d0b..d58f171d 100644 --- a/inst/tinytest/test-tinytheme.R +++ b/inst/tinytest/test-tinytheme.R @@ -166,4 +166,11 @@ f = function() { plt_add(type = "lm") par(opar) } -expect_snapshot_plot(f, label = "tinytheme_ephemeral") \ No newline at end of file +expect_snapshot_plot(f, label = "tinytheme_ephemeral") + +# Ephemeral "default" theme with by + plt_add should not clip (#557) +f = function() { + plt(1:3, c(1, 1, 1), by = c("a", "a", "a"), theme = "default", type = "n") + plt_add(type = "b") +} +expect_snapshot_plot(f, label = "ephemeral_default_theme_add")