diff --git a/NEWS.md b/NEWS.md index 201df9d8..861f48d9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -159,6 +159,8 @@ related to plot layering. See "Bug fixes" below. ### Bug fixes +- `type_ridge()` no longer errors under themes that set a relative (negative) + numeric `col.default`, e.g. `theme = "classic"`. (#703 @grantmcdermott) - Layers added with `tinyplot_add()` now align correctly when the base plot type coerces a numeric `x` variable to a factor, as `type_barplot()` and `type_violin()` do. The base layer's categories are the coerced *labels*, diff --git a/R/type_ridge.R b/R/type_ridge.R index ef33b613..c30257ae 100644 --- a/R/type_ridge.R +++ b/R/type_ridge.R @@ -456,14 +456,17 @@ data_ridge = function(bw = "nrd0", adjust = 1, kernel = "gaussian", n = 512, breaks[length(breaks)] = pmax(breaks[length(breaks)], xlim[2L]) } - # Single-group (or x_by) ridges: default the outline colour consistently - # with the other plot types. An explicit `col.default` wins; otherwise fall - # back to the first colour of the active qualitative palette (e.g. blue under - # "clean"), or base palette()[1] (black) when no theme palette is set. (#598) - if (is.null(col) && (!anyby || x_by)) { - col = get_tpar("col.default", default = NULL) + # `x_by` shades with a gradient along x, so `by_col()` returns a colour ramp + # rather than a flat outline (and skips `col.default`, which is qualitative- + # only). Resolve it here; every other case is left to `by_col()`. (#598) + if (is.null(col) && x_by) { + pal_q = .tpar[["palette.qualitative"]] + # `col.default` may be a (possibly negative) palette index, not a literal + # colour, so resolve it the way `by_col()` does. (#703) + col = resolve_col_default( + get_tpar("col.default", default = NULL), pal_q + )[["col_default"]] if (is.null(col)) { - pal_q = .tpar[["palette.qualitative"]] col = if (!is.null(pal_q)) { resolve_palette_spec( pal_q, ngrps = 1L, gradient = FALSE, ordered = FALSE, diff --git a/inst/tinytest/_tinysnapshot/ridge_theme_col_default_issue703.svg b/inst/tinytest/_tinysnapshot/ridge_theme_col_default_issue703.svg new file mode 100644 index 00000000..48b5bc62 --- /dev/null +++ b/inst/tinytest/_tinysnapshot/ridge_theme_col_default_issue703.svg @@ -0,0 +1,71 @@ + + + + + + + + + + + + + +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 0ed6fb47..71613b6e 100644 --- a/inst/tinytest/test-type_ridge.R +++ b/inst/tinytest/test-type_ridge.R @@ -170,6 +170,13 @@ f = function() { } expect_snapshot_plot(f, label = "ridge_ylab_na_issue650") +# Issue #703: a numeric (relative) `col.default`, e.g. -1 under "classic", must +# resolve against the qualitative palette, not pass through as a literal colour. +f = function() { + tinyplot(Species ~ Sepal.Width, data = iris, type = "ridge", theme = "classic") +} +expect_snapshot_plot(f, label = "ridge_theme_col_default_issue703") + # ## singleton groups (#300)