CMAP-REPOS / cmapplot

Set of templates and themes to apply CMAP graphics standards to R products.
https://cmap-repos.github.io/cmapplot/
Other
13 stars 1 forks source link

Remove unused race/ethnicity categories from legend #142

Closed nmpeterson closed 1 year ago

nmpeterson commented 2 years ago

Currently, if you create a chart using cmap_color_race(), the resulting legend will display all five categories (white, black, hispanic, asian, other), even if one of those categories is not present in the data/chart:

race_legend

I think there are two possible approaches for addressing this:

  1. Remove any default labels for the race/ethnicity categories, and only construct the palette from the label names that are explicitly supplied to cmap_color_race(). So cmap_color_race(white = "White", black = "Black") would yield a 2-item legend instead of 5 (with "hispanic", "asian" and "other" appearing by default). If none of the parameters were specified, an error would be returned saying that at least one must be.
  2. Add a new remove_missing boolean parameter. If it defaulted to FALSE, then cmap_color_race(white = "White", black = "Black") would still produce the same 5-item legend as the current function, but cmap_color_race(white = "White", black = "Black", remove_missing = TRUE) would then produce a 2-item legend.

I don't have strong feelings one way or the other. I'd be particularly interested to hear @gritzenthaler's thoughts on this one.