From 215b34e7510cb65e5c10a6f1ce3bf7e47deb1d2a Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Wed, 25 Mar 2026 16:46:57 -0700 Subject: [PATCH 1/5] catch for qualitiative theme palette --- R/type_ridge.R | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/R/type_ridge.R b/R/type_ridge.R index 605a0c40..4daf6da3 100644 --- a/R/type_ridge.R +++ b/R/type_ridge.R @@ -441,14 +441,22 @@ draw_ridge = function() { ridge_theme = identical(.tpar[["tinytheme"]], "ridge") || identical(.tpar[["tinytheme"]], "ridge2") d = data.frame(x = ix, y = iy, ymin = iymin, ymax = iymax) dsplit = split(d, d$y) + if (!is.null(type_info[["col"]])) icol = type_info[["col"]] if (is.null(ibg)) { - default_bg = if (!ridge_theme && !is.null(.tpar[["palette.qualitative"]])) seq_palette(by_col(), n = 2)[2] else "gray" + pal_q = .tpar[["palette.qualitative"]] + # For non-ridge themes with a palette, derive fill from the first palette + # colour. We need palette.colors() here because the palette is still just + # a string name at this point (not yet resolved to colours). (#547) + default_bg = if (!ridge_theme && !is.null(pal_q)) { + seq_palette(palette.colors(1, palette = pal_q), n = 2)[2] + } else { + "gray" + } ibg = if (isTRUE(type_info[["fill_by"]])) seq_palette(icol, n = 2)[2] else default_bg } if (!is.null(type_info[["alpha"]]) && is.null(type_info[["palette"]])) { ibg = adjustcolor(ibg, alpha.f = type_info[["alpha"]]) } - if (!is.null(type_info[["col"]])) icol = type_info[["col"]] lab = if (is.factor(d$y)) levels(d$y) else unique(d$y) if (isTRUE(type_info[["y_by"]])) { # avoid duplicating the y-axis labs for the special y==by case From 552c44e9da8c513294329adbcb054f8d8ed4b884 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Wed, 25 Mar 2026 16:47:04 -0700 Subject: [PATCH 2/5] tests --- .../_tinysnapshot/ridge_theme_palette.svg | 73 +++++++++++++++++++ inst/tinytest/test-type_ridge.R | 8 +- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 inst/tinytest/_tinysnapshot/ridge_theme_palette.svg diff --git a/inst/tinytest/_tinysnapshot/ridge_theme_palette.svg b/inst/tinytest/_tinysnapshot/ridge_theme_palette.svg new file mode 100644 index 00000000..7138677a --- /dev/null +++ b/inst/tinytest/_tinysnapshot/ridge_theme_palette.svg @@ -0,0 +1,73 @@ + + + + + + + + + + + + + +Sepal.Width +Species +1.5 +2.0 +2.5 +3.0 +3.5 +4.0 +4.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +setosa +versicolor +virginica + + + diff --git a/inst/tinytest/test-type_ridge.R b/inst/tinytest/test-type_ridge.R index 18e4b902..7a4587a5 100644 --- a/inst/tinytest/test-type_ridge.R +++ b/inst/tinytest/test-type_ridge.R @@ -147,4 +147,10 @@ f = function() { col = "white" ) } -expect_snapshot_plot(f, label = "ridge_gradient_facet_raster_alpha") \ No newline at end of file +expect_snapshot_plot(f, label = "ridge_gradient_facet_raster_alpha") + +# Issue #547: ridge with themed palette should not error +f = function() { + tinyplot(Species ~ Sepal.Width, data = iris, type = "ridge", theme = "clean2") +} +expect_snapshot_plot(f, label = "ridge_theme_palette") From 3eb1cea6e66d3e03401c19b7048c3dd4912b36f2 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Wed, 25 Mar 2026 16:58:27 -0700 Subject: [PATCH 3/5] gotcha for transparent background with 'ridge' (no groups) --- R/type_ridge.R | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/R/type_ridge.R b/R/type_ridge.R index 4daf6da3..946863d5 100644 --- a/R/type_ridge.R +++ b/R/type_ridge.R @@ -396,6 +396,16 @@ data_ridge = function(bw = "nrd0", adjust = 1, kernel = "gaussian", n = 512, if (is.null(col) && (!anyby || x_by)) col = "black" + # For ridge themes without groups, a numeric bg (e.g. bg = 0.2) should + # produce transparent gray, not a transparent palette colour. (#547) + ridge_theme = identical(.tpar[["tinytheme"]], "ridge") || identical(.tpar[["tinytheme"]], "ridge2") + if (ridge_theme && !anyby) { + ubg = settings[["bg"]] + if (!is.null(ubg) && length(ubg) == 1 && is.numeric(ubg) && ubg >= 0 && ubg <= 1) { + settings[["bg"]] = adjustcolor("gray", alpha.f = ubg) + } + } + # Save original yaxt for type_info before overwriting yaxt_orig = yaxt yaxt = "n" @@ -408,6 +418,7 @@ data_ridge = function(bw = "nrd0", adjust = 1, kernel = "gaussian", n = 512, manbreaks = manbreaks, yaxt = yaxt_orig, raster = raster, + ridge_theme = ridge_theme, x_by = x_by, y_by = y_by, fill_by = fill_by, @@ -438,7 +449,7 @@ data_ridge = function(bw = "nrd0", adjust = 1, kernel = "gaussian", n = 512, ## Underlying draw_ridge function draw_ridge = function() { fun = function(ix, iy, iz, ibg, icol, iymin, iymax, type_info, ...) { - ridge_theme = identical(.tpar[["tinytheme"]], "ridge") || identical(.tpar[["tinytheme"]], "ridge2") + ridge_theme = isTRUE(type_info[["ridge_theme"]]) d = data.frame(x = ix, y = iy, ymin = iymin, ymax = iymax) dsplit = split(d, d$y) if (!is.null(type_info[["col"]])) icol = type_info[["col"]] From e3991b886fd1d5e355616421ac9acd83287d0235 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Wed, 25 Mar 2026 17:02:38 -0700 Subject: [PATCH 4/5] test --- .../_tinysnapshot/ridge_theme_bg_numeric.svg | 69 +++++++++++++++++++ inst/tinytest/test-type_ridge.R | 6 ++ 2 files changed, 75 insertions(+) create mode 100644 inst/tinytest/_tinysnapshot/ridge_theme_bg_numeric.svg diff --git a/inst/tinytest/_tinysnapshot/ridge_theme_bg_numeric.svg b/inst/tinytest/_tinysnapshot/ridge_theme_bg_numeric.svg new file mode 100644 index 00000000..7acdb280 --- /dev/null +++ b/inst/tinytest/_tinysnapshot/ridge_theme_bg_numeric.svg @@ -0,0 +1,69 @@ + + + + + + + + + + + + + +Sepal.Width +Species +1.5 +2.0 +2.5 +3.0 +3.5 +4.0 +4.5 + + + + + + + + + + + + + + + + + + +setosa +versicolor +virginica + + + + + + + + + + + diff --git a/inst/tinytest/test-type_ridge.R b/inst/tinytest/test-type_ridge.R index 7a4587a5..eef900fc 100644 --- a/inst/tinytest/test-type_ridge.R +++ b/inst/tinytest/test-type_ridge.R @@ -154,3 +154,9 @@ f = function() { tinyplot(Species ~ Sepal.Width, data = iris, type = "ridge", theme = "clean2") } expect_snapshot_plot(f, label = "ridge_theme_palette") + +# Issue #547: numeric bg with ridge theme should produce transparent gray +f = function() { + tinyplot(Species ~ Sepal.Width, data = iris, type = "ridge", theme = "ridge2", bg = 0.2) +} +expect_snapshot_plot(f, label = "ridge_theme_bg_numeric") From 67e9d6421c6ed59e5c9812d5c484312dd0e300b9 Mon Sep 17 00:00:00 2001 From: Grant McDermott Date: Wed, 25 Mar 2026 17:06:45 -0700 Subject: [PATCH 5/5] news --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index 42153052..a6d67cba 100644 --- a/NEWS.md +++ b/NEWS.md @@ -31,6 +31,9 @@ where the formatting is also better._ - Jitter layers added via `tinyplot_add()` now align correctly with grouped (offset) boxplot, violin, and ridge base layers. (#493 @grantmcdermott) +- Fixed `type_ridge()` fill errors for themes that set a qualitative palette, + e.g. `"clean2"`. (#564 @grantmcdermott) + ### Internals - We now encourage type-specific legend customizations within the individual