Skip to content

Conversation

@jack-davison
Copy link
Collaborator

This is a bit of a rewrite of openColours() that does three main things:

Reversing Palettes

  • openColours() gains direction in line with other colour packages like viridis/RColorBrewer/etc. When direction is -1, you get a reversed palette.

  • If you provide a scheme with a - at the front, e.g., "-Dark", this reverses direction. This is to make it more convenient to use in other openair functions - e.g.,

timeProp(mydata, "no2", proportion = "wd", avg.time = "month", cols = "Dark2")
image
timeProp(mydata, "no2", proportion = "wd", avg.time = "month", cols = "-Dark2")
image

Streamlining Palette Behaviour

  • Formerly there were sequential palettes, diverging palettes, qualitative palettes, brewer palettes, hue, greyscale, and a few others. This PR recategorizes everything as either diverging/sequential or qualitative. This has a few benefits:

    • It is easier to add new palettes, because they will slot into one or the other category.

    • We can delete RColorBrewer.R - the simplified setup fits everything in one file.

    • All palettes will behave consistently to one another. The clearest example of this is the interpolation of qualitative palettes, which only occurred for the brewer palettes but not for other qualitative palettes. Now all qualitative palettes will interpolate, with warnings given if interpolation is occurring.

# interpolate, but complain about it
timeProp(
  mydata,
  "no2",
  proportion = "o3",
  avg.time = "month",
  cols = "observable",
  n.levels = 15
)
Warning messages:
1: ! Removing 2589 rows due to missing `o3` data. 
2: ! Too many colours selected for `observable`.
ℹ `n` should be between 1 and 10.
ℹ Colours will be interpolated to produce 12 colours. 
image

Managing Schemes through an R Object

  • This PR exports a dataframe, openSchemes, which lists all of schemes available in openColours().
> openSchemes
# A tibble: 61 × 6
   category scheme   max_n colorblind origin       reference               
   <chr>    <chr>    <dbl> <lgl>      <chr>        <chr>                   
 1 div      BrBG        NA TRUE       RColorBrewer https://colorbrewer2.org
 2 div      PRGn        NA TRUE       RColorBrewer https://colorbrewer2.org
 3 div      PiYG        NA TRUE       RColorBrewer https://colorbrewer2.org
 4 div      PuOr        NA TRUE       RColorBrewer https://colorbrewer2.org
 5 div      RdBu        NA TRUE       RColorBrewer https://colorbrewer2.org
 6 div      RdGy        NA FALSE      RColorBrewer https://colorbrewer2.org
 7 div      RdYlBu      NA TRUE       RColorBrewer https://colorbrewer2.org
 8 div      RdYlGn      NA FALSE      RColorBrewer https://colorbrewer2.org
 9 div      Spectral    NA FALSE      RColorBrewer https://colorbrewer2.org
10 qual     Accent       8 FALSE      RColorBrewer https://colorbrewer2.org
# ℹ 51 more rows
# ℹ Use `print(n = ...)` to see more rows
  • Programmatic access to colour palettes is useful for a lot of reasons, e.g., for Shiny Apps to list available colour palettes to the user.
image
  • "Interactive" users can also filter the dataframe just to see what their options are - e.g., filter for qualitative palettes with at least n unique colours

@jack-davison jack-davison self-assigned this Oct 13, 2025
@jack-davison jack-davison added enhancement Ideas for new features for openair refactor Non user-facing changes utilities 🛠 Openair data utilities, e.g., timeAverage and removed refactor Non user-facing changes labels Oct 13, 2025
@jack-davison jack-davison marked this pull request as ready for review October 16, 2025 07:07
@jack-davison jack-davison marked this pull request as draft November 10, 2025 17:24
@jack-davison
Copy link
Collaborator Author

Hue is fixed.

I have also:

  • added too_few to manage the situation where insufficient colours are in a palette (either interpolate, repeat, or error).

  • added a lot of palettes from khroma based on Fabio Crameri (and a few more by Paul Tol).

@jack-davison jack-davison marked this pull request as ready for review November 11, 2025 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Ideas for new features for openair utilities 🛠 Openair data utilities, e.g., timeAverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants