Closed grantmcdermott closed 10 months ago
Yes, I agree. This should work in https://github.com/grantmcdermott/plot2/blob/main/R/by_aesthetics.R#L42-L46
fx <- function(x) tolower(gsub("[-, _, \\,, (, ), \\ , \\.]", "", x))
if (!is.na(charmatch(fx(palette), fx(palette.pals())))) {
palette_fun = palette.colors
} else if (!is.na(charmatch(fx(palette), fx(hcl.pals())))) {
palette_fun = hcl.colors
} else {
...
I'm happy to turn this into a proper PR but it may take a couple of days. Hence I wanted to put it here before I forget.
We currently allow for palette matching regardless of case (e.g., "r4" <-> "R4").
But, unlike, the main
palette()
andhcl.colors()
functions, we don't do a good job of partial matching (e.g., with an unambiguous first word likepalette("tableau")
orhcl.colors(5, "zissou")
). It's probably a good idea just to use the samecharmatch
approach that the latter two functions have adopted internally.