colorize: Add colors by category

View source: R/colorize.R

colorizeR Documentation

Add colors by category

Description

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.

Usage

colorize(x)

Arguments

x

Categorical. Used to base the coloring of the observations on. For now must have 12 or fewer categories to work.

Value

When used with mutate, the function returns a variable where each observation is assigned a color based on the categories of a categorical variable.

Examples

mt_colors <- mutate(mtcars, colors = colorize(cyl))
head(mt_colors$colors)
xyplot(hp ~ disp, data = mt_colors, groups = colors)


mobilizingcs/mobilizr documentation built on Feb. 17, 2024, 7:49 p.m.