map_to_colors() maps a vector of data values to a vector of hexadecimal color codes based on a specified color theme.
It automatically handles both discrete and continuous variables, appropriately scaling values and handling missing data.
Arguments
- x
a vector of data values (discrete or continuous) to be mapped to colors.
- theme
a color theme name (e.g.,
"Viridis"), a"colortheme"object, a character vector of color names, or a palette/ramp function. Seecolorthemefor details.- discrete
logical. If
TRUE, a discrete scale is used regardless of the data type and the theme type.- middle
a numeric value specifying the midpoint for diverging color themes. Default is
0.- na.value
a character string specifying the color for
NAvalues. IfNULL(default), falls back to the theme'sna.coloroption.

