colorize | R Documentation |
A simple function to add a variable of colors to a data frame based on a
separate categorical variable. Designed to be used within the dplyr
mutate
funciton.
colorize(x)
x |
Categorical. Used to base the coloring of the observations on. For now must have 12 or fewer categories to work. |
When used with mutate
, the function returns a variable where
each observation is assigned a color based on the categories of a
categorical variable.
mt_colors <- mutate(mtcars, colors = colorize(cyl))
head(mt_colors$colors)
xyplot(hp ~ disp, data = mt_colors, groups = colors)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.