Skip to content

Customize lighter colors for area-based displays #659

Description

@zeileis

Follow-up to #657 and #646

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions