Skip to content

Consistent fill lighten for area types#657

Merged
grantmcdermott merged 18 commits into
mainfrom
issue646-lighten
Jul 3, 2026
Merged

Consistent fill lighten for area types#657
grantmcdermott merged 18 commits into
mainfrom
issue646-lighten

Conversation

@grantmcdermott

@grantmcdermott grantmcdermott commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Closes #646

Using the same summary that I shared in my earlier comment:

  • Grouped barplot, boxplot, and violin now use the same lighter-but-opaque fill as their single-group counterparts. This fixes the the original inconsistency that you pointed out at the top of this issue (dark saturated bars vs. semi-transparent boxes).
    • The way that this works is that each of these types gains a lighten argument (default TRUE). So, for example, you could override with type_barplot(lighten = FALSE) to fall back to the old saturated palette colour.
    • spineplot also gets a similar lightening treatment, but only for the special y == by case. I've also made sure that these get consistent (black) borders regardless of grouping.
  • The alpha-darkening bug is fixed. We now resolve the palette opaque, lighten, and then layer any transparency on top.s fixed.

MWE

Using some of the examples from the original issues:

pkgload::load_all("~/Documents/Projects/tinyplot/")
#> ℹ Loading tinyplot
tinytheme("clean2")
tinyplot(~ species, data = penguins)

tinyplot(~ species | island, data = penguins)

tinyplot(body_mass ~ species, data = penguins)

tinyplot(body_mass ~ species | sex, data = penguins)

tinyplot(~ species, data = penguins)

tinyplot(~ species, data = penguins, fill = 0.7)

Created on 2026-07-01 with reprex v2.1.1

@grantmcdermott grantmcdermott requested a review from zeileis July 2, 2026 00:56
@zeileis

zeileis commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

To support specifications like lighten = 0.5 in addition to just lighten = TRUE we could use:

lighten_col = function(x, amount = 0.8) {
  x = to_hcl(x)
  hcl(
    h = x[, "H"],
    c = x[, "C"] * (1 - amount),
    l = 100 - (100 - x[, "L"]) * (1 - amount),
    alpha = attr(x, "alpha")
  )
}

By default this yields similar colors as the current lighten_fill() which is based on seq_palette(..., n = 3)[3]. Because we just need the lightened color here (rather than a palette going from the full color to the lightened one), lighten_col() can be a little bit simpler and hence leads to slightly different output.

Additionally, we may want to build in a catch that makes sure that lighten_col("black") returns "lightgray" to be exactly consistent with base R.

@grantmcdermott

Copy link
Copy Markdown
Owner Author

Thanks @zeileis, I think that both lighten = [0,1] and lighten_col are good ideas... But I'm afraid that I'm up against a hard deadline and so will have to defer to until a later date.

(tl;dr I'm leaving for 3 weeks vacation, with limited computer access. But I have to get this next CRAN submission out first, so that some work colleagues can easily use v0.7.0 for an internal project while I'm gone. It's a long story, but they need some our latest features and also have to install from the official CRAN distribution for some infosec reasons.)

Anyway, the bottom line is that I need to merge this today if it's going to make the v0.7.0 submission. IMHO it should be included if at all possible and I also feel it's basically in good enough shape now. But I can hold off until later today if you need/want to confirm anything else on your side.

Let me know!

@grantmcdermott

Copy link
Copy Markdown
Owner Author

P.S. I realize that I didn't include any spineplot MWEs above. I was probably unnecessarily confusing in my previous comment #646 (comment)... The takehome version is that, for most cases, spineplots are essentially unchanged. The only user-facing changes that I implemented were:

  1. We now draw black borders by default for all spineplots; whereas we previously turned these off automagically for some plots. Note that users can still turn borders off manually, by calling (say) lty = 0. This feels more principled to me.
pkgload::load_all("~/Documents/Projects/tinyplot/")
#> ℹ Loading tinyplot
tinytheme("clean2")
tinyplot(
  Species ~ Sepal.Length, data = iris, 
  type = "spineplot"
)

tinyplot(
  Species ~ Sepal.Length, data = iris,
  type = "spineplot", lty = 0
)

  1. Users have the option to call lighten = TRUE for spineplots where y==by (and only for this narrow case). This argument is set to FALSE by default, but I felt it made sense to add the option give our other updates to barplot and co. above (although the default for these other types is obviously TRUE).
tinyplot(
  Species ~ Sepal.Length | Species, data = iris,
  type = "spineplot"
)

tinyplot(
  Species ~ Sepal.Length | Species, data = iris,
  type = type_spineplot(lighten = TRUE)
)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses #646 by making multi-group area-based plot types use consistent lighter-but-opaque fills (matching the single-group look), while introducing an explicit lighten toggle to opt out where appropriate (and keeping histogram/spineplot defaults aligned with their visual constraints).

Changes:

  • Add lighten support to barplot, boxplot, and violin types (default TRUE) and update fill/alpha layering so numeric fill/alpha applies on top of the (optionally lightened) base fill.
  • Add lighten support to spineplot (default FALSE, only meaningful for the y == by case) and adjust legend fill resolution for grouped spineplots.
  • Update documentation, vignettes, tests, and snapshot artifacts to reflect the new defaults and options.

Reviewed changes

Copilot reviewed 22 out of 61 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
vignettes/gallery_figs/spineplot-titanic.R Adjusts gallery figure params to match updated spineplot/legend styling.
vignettes/gallery_figs/likert.R Uses type_barplot(lighten = FALSE, ...) to preserve intended saturated fills in the likert example.
vignettes/gallery_figs/barplot-meat.R Demonstrates opting out of fill lightening for barplots in gallery output.
R/zzz.R Adds lighten to the recognized argument set used across the package.
R/type_violin.R Introduces lighten parameter plumbed into violin type data for consistent grouped fills.
R/type_spineplot.R Adds lighten option for y == by spineplots and refines frame/legend behavior.
R/type_boxplot.R Introduces lighten parameter for boxplots and routes it into type data.
R/type_barplot.R Introduces lighten parameter for barplots and routes it into type data.
R/tinyplot.R Adds a global settings$lighten default used by grouped-fill resolution.
R/legend.R Ensures grouped spineplot legends mirror plotted fill behavior (including lightening).
NEWS.md Documents the grouped-fill consistency change and new lighten options.
man/type_violin.Rd Updates generated docs for new violin behavior/arguments.
man/type_spineplot.Rd Updates generated docs for new spineplot behavior/arguments.
man/type_boxplot.Rd Updates generated docs for new boxplot behavior/arguments.
man/type_barplot.Rd Updates generated docs for new barplot behavior/arguments.
inst/tinytest/test-type_violin.R Updates violin snapshot tests for new defaults and adds lighten = FALSE coverage.
inst/tinytest/test-type_spineplot.R Updates spineplot snapshot tests and adds lighten = TRUE coverage for y == by.
inst/tinytest/test-type_boxplot.R Adds snapshot coverage for type_boxplot(lighten = FALSE).
inst/tinytest/test-type_barplot.R Updates barplot snapshot tests for new defaults and adds lighten = FALSE coverage.
inst/tinytest/test-tinyplot_add.R Updates jitter-layer snapshots impacted by new fill/alpha behavior.
inst/tinytest/_tinysnapshot/spineplot_yby.svg Snapshot update reflecting spineplot legend/frame styling changes.
inst/tinytest/_tinysnapshot/spineplot_yby_lighten_true.svg New snapshot for spineplot with lighten = TRUE in the y == by case.
inst/tinytest/_tinysnapshot/spineplot_yby_lighten_false.svg New snapshot for spineplot with lighten = FALSE in the y == by case.
inst/tinytest/_tinysnapshot/spineplot_xby.svg Snapshot update reflecting spineplot legend/frame styling changes.
inst/tinytest/_tinysnapshot/spineplot_facet_by.svg Snapshot update reflecting spineplot legend/frame styling changes.
inst/tinytest/_tinysnapshot/boxplot_groups.svg Snapshot update for new grouped boxplot fill behavior.
inst/tinytest/_tinysnapshot/boxplot_groups_x_same.svg Snapshot update for new grouped boxplot fill behavior.
inst/tinytest/_tinysnapshot/boxplot_groups_x_same_legendFALSE.svg Snapshot update for new grouped boxplot fill behavior without legend.
inst/tinytest/_tinysnapshot/boxplot_groups_x_equivalent.svg Snapshot update for new grouped boxplot fill behavior.
inst/tinytest/_tinysnapshot/boxplot_groups_x_equivalent_legendFALSE.svg Snapshot update for new grouped boxplot fill behavior without legend.
inst/tinytest/_tinysnapshot/boxplot_groups_lighten_false.svg New snapshot for grouped boxplot with lighten = FALSE.
inst/tinytest/_tinysnapshot/boxplot_groups_facets_with_missings.svg Snapshot update for new grouped boxplot fill behavior with facets/missings.
inst/tinytest/_tinysnapshot/boxplot_groups_argpass.svg Snapshot update for grouped boxplot argument-passing case under new fill behavior.
inst/tinytest/_tinysnapshot/boxplot_facet_by_x_same.svg Snapshot update for faceted grouped boxplot under new fill behavior.
inst/tinytest/_tinysnapshot/barplot_offset_stacked.svg Snapshot update for barplot offset example under new fill behavior.
inst/tinytest/_tinysnapshot/barplot_offset_beside_group.svg Snapshot update for barplot offset/beside grouped example under new fill behavior.
inst/tinytest/_tinysnapshot/barplot_group.svg Snapshot update for grouped barplot under new default lightened fills.
inst/tinytest/_tinysnapshot/barplot_group_lighten_false.svg New snapshot for grouped barplot with lighten = FALSE.
inst/tinytest/_tinysnapshot/barplot_group_beside.svg Snapshot update for grouped barplot (beside) under new fill behavior.
inst/tinytest/_tinysnapshot/barplot_flip_fancy.svg Snapshot update for flipped “fancy” barplot under new fill behavior.
inst/tinytest/_tinysnapshot/barplot_facet.svg Snapshot update for faceted barplot under new fill behavior.
inst/tinytest/_tinysnapshot/barplot_facet_free.svg Snapshot update for faceted free-scale barplot under new fill behavior.
inst/tinytest/_tinysnapshot/barplot_custom_ytitle.svg Snapshot update for custom-title barplot under new fill behavior.
inst/tinytest/_tinysnapshot/barplot_custom_xtitle.svg Snapshot update for custom-title barplot under new fill behavior.
inst/tinytest/_tinysnapshot/barplot_aggregation.svg Snapshot update for aggregated barplot under new fill behavior.
altdoc/pkgdown.yml Updates pkgdown build timestamp metadata.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread R/type_spineplot.R Outdated
Comment thread man/type_spineplot.Rd Outdated
Comment thread R/type_violin.R Outdated
Comment thread man/type_violin.Rd Outdated
Comment thread R/type_boxplot.R Outdated
Comment thread man/type_boxplot.Rd Outdated
Comment thread R/type_boxplot.R
Comment thread man/type_boxplot.Rd
Comment thread NEWS.md
@grantmcdermott grantmcdermott merged commit 808b1e4 into main Jul 3, 2026
3 checks passed
@grantmcdermott grantmcdermott deleted the issue646-lighten branch July 3, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Area-based plot types: light opaque multi-group color

3 participants