Skip to content

Consistent fill lighten for area types#657

Open
grantmcdermott wants to merge 10 commits into
mainfrom
issue646-lighten
Open

Consistent fill lighten for area types#657
grantmcdermott wants to merge 10 commits into
mainfrom
issue646-lighten

Conversation

@grantmcdermott

@grantmcdermott grantmcdermott commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Closes #646

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.

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

2 participants