Control single- vs multi-group palettes via col.default#614
Control single- vs multi-group palettes via col.default#614grantmcdermott wants to merge 10 commits into
col.default#614Conversation
There was a problem hiding this comment.
Pull request overview
Implements a new theme/tpar parameter (col.default) to control default colors for single-group (no by) plots versus multi-group palettes, and updates multiple plot types/themes to apply this logic consistently (Issue #598).
Changes:
- Add
tpar/theme support forcol.defaultand validate it intpar. - Update color/fill resolution for single-group displays (notably ridge outlines and box/violin/bar fills under active theme palettes).
- Expand snapshot tests to lock in per-theme single-group default color behavior.
Reviewed changes
Copilot reviewed 13 out of 45 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| R/type_violin.R | Adjust single-group fill default so theme palettes can drive fill via resolved border color. |
| R/type_ridge.R | Respect top-level col, add col.default fallback for single-group ridge outlines, and robustly resolve theme palettes to colors. |
| R/type_histogram.R | Removes hard-coded single-group border default (but see review comment about by/null_by handling). |
| R/type_boxplot.R | Adjust single-group fill default so theme palettes can drive fill via resolved border color. |
| R/type_barplot.R | Adjust single-group fill default so theme palettes can drive fill via resolved border color. |
| R/tpar.R | Document, register, validate, and initialize new col.default tpar option. |
| R/tinytheme.R | Introduce “no-black” palette variants and set per-theme col.default / palette tweaks to separate single vs grouped defaults. |
| R/by_aesthetics.R | Add col.default hook for single-group color resolution and make single-group fills track resolved border color for selected types. |
| NEWS.md | Document new single- vs multi-group default color behavior and theme palette adjustments. |
| man/type_ridge.Rd | Update docs to explain ridge outline color precedence and col.default fallback chain. |
| man/tpar.Rd | Document col.default. |
| inst/tinytest/test-type_ridge.R | Update/extend snapshot coverage for ridge gradient cases and outline color overrides. |
| inst/tinytest/test-tinytheme.R | Add snapshot loop for single-group plots across all built-in themes. |
| inst/tinytest/_tinysnapshot/tinytheme_single_web.svg | New snapshot for single-group default under web. |
| inst/tinytest/_tinysnapshot/tinytheme_single_void.svg | New snapshot for single-group default under void. |
| inst/tinytest/_tinysnapshot/tinytheme_single_ridge2.svg | New snapshot for single-group default under ridge2. |
| inst/tinytest/_tinysnapshot/tinytheme_single_ridge.svg | New snapshot for single-group default under ridge. |
| inst/tinytest/_tinysnapshot/tinytheme_single_nber.svg | New snapshot for single-group default under nber. |
| inst/tinytest/_tinysnapshot/tinytheme_single_minimal.svg | New snapshot for single-group default under minimal. |
| inst/tinytest/_tinysnapshot/tinytheme_single_ipsum2.svg | New snapshot for single-group default under ipsum2. |
| inst/tinytest/_tinysnapshot/tinytheme_single_ipsum.svg | New snapshot for single-group default under ipsum. |
| inst/tinytest/_tinysnapshot/tinytheme_single_float.svg | New snapshot for single-group default under float. |
| inst/tinytest/_tinysnapshot/tinytheme_single_dynamic.svg | New snapshot for single-group default under dynamic. |
| inst/tinytest/_tinysnapshot/tinytheme_single_default.svg | New snapshot for single-group default under default. |
| inst/tinytest/_tinysnapshot/tinytheme_single_dark.svg | New snapshot for single-group default under dark. |
| inst/tinytest/_tinysnapshot/tinytheme_single_clean2.svg | New snapshot for single-group default under clean2. |
| inst/tinytest/_tinysnapshot/tinytheme_single_clean.svg | New snapshot for single-group default under clean. |
| inst/tinytest/_tinysnapshot/tinytheme_single_classic.svg | New snapshot for single-group default under classic. |
| inst/tinytest/_tinysnapshot/tinytheme_single_broadsheet.svg | New snapshot for single-group default under broadsheet. |
| inst/tinytest/_tinysnapshot/tinytheme_single_basic.svg | New snapshot for single-group default under basic. |
| inst/tinytest/_tinysnapshot/tinytheme_minimal.svg | Update snapshot to reflect new grouped palette behavior under minimal. |
| inst/tinytest/_tinysnapshot/tinytheme_linedraw.svg | Update snapshot to reflect new grouped palette behavior under linedraw. |
| inst/tinytest/_tinysnapshot/tinytheme_ipsum2.svg | Update snapshot to reflect new grouped palette behavior under ipsum2. |
| inst/tinytest/_tinysnapshot/tinytheme_classic.svg | Update snapshot to reflect new grouped palette behavior under classic. |
| inst/tinytest/_tinysnapshot/tinytheme_bw.svg | Update snapshot to reflect new grouped palette behavior under bw. |
| inst/tinytest/_tinysnapshot/tinytheme_broadsheet.svg | Update snapshot to reflect new grouped palette behavior under broadsheet. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
P.S. Here are some example, using your four plot case from #598 First, the default (no) theme: pkgload::load_all("~/Documents/Projects/tinyplot/")
#> ℹ Loading tinyplot
par(mfrow = c(2,2))
tinyplot(gear ~ 1, data = mtcars)
tinyplot(factor(gear) ~ 1, data = mtcars)
tinyplot(mpg ~ gear, data = mtcars)
tinyplot(mpg ~ factor(gear), data = mtcars)Second, using tinytheme("clean2")
tinyplot(gear ~ 1, data = mtcars)
tinyplot(factor(gear) ~ 1, data = mtcars)
tinyplot(mpg ~ gear, data = mtcars)
tinyplot(mpg ~ factor(gear), data = mtcars)Third, using tinytheme("ipsum")
tinyplot(gear ~ 1, data = mtcars)
tinyplot(factor(gear) ~ 1, data = mtcars)
tinyplot(mpg ~ gear, data = mtcars)
tinyplot(mpg ~ factor(gear), data = mtcars) |
|
@vincentarelbundock I realized that you might to take a look at this too, since it will effect behaviour for some themes. |
|
oh yeah, that seems like a good idea to me! I like the examples a lot. |
|
Thanks, Grant @grantmcdermott! Sorry for the slow follow-up...the last weeks were very busy with the preparations for our World Cup forecast and corresponding press work. Regarding the
Regarding plots with shaded areas such as
|
|
I think it would be nice to support which should mean: use the first color from the palette as the default color and take it out of the qualitative palette afterwards. Then we don't need to keep around extra copies of palettes without black. In order to resolve this we would have to add something like the following code somewhere in the |



Closes #598
@zeileis this PR implements your idea for a new
col.defaultparameter that controls the behaviour for single- versus mulii-group displays. I've enacted it for most (but not all) themes, using the following heuristic:col.default = "black" on for themes that, until now, had a qualitative palette starting with black. This includes the Okabe-Ito-based themes ("bw","ipsum2","broadsheet",etc.), plus a few others that conceptually favour a monochrome single series ("ipsum","socviz", etc.)"clean(2)","dark","web"), we leavecol.defaultasNULLso they always use the first colour of their (existing) palette."default","basic", etc.) are unchanged: single-group displays fall back to base Rpalette()[1](i.e., black).In table form:
col.defaultpalette()(black)