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:
I think there are two possible approaches for addressing this:
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.
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.
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:I think there are two possible approaches for addressing this:
cmap_color_race()
. Socmap_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.remove_missing
boolean parameter. If it defaulted toFALSE
, thencmap_color_race(white = "White", black = "Black")
would still produce the same 5-item legend as the current function, butcmap_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.