# Generate Attractive Random Colors

Simple methods to generate attractive random colors. The random colors are from a wrapper of 'randomColor.js' < https://github.com/davidmerfield/randomColor>. In addition, it also generates optimally distinct colors based on k-means (inspired by 'IWantHue' < https://github.com/medialab/iwanthue>).

An R package for generating attractive and distinctive colors.

The `randomColor()` function is ported from randomColor.js.

Let's quickly get some pretty random colors.

``library(igraph)library(randomcoloR) k <- 200plot(erdos.renyi.game(k, 0.1), vertex.label=NA,     edge.lty="blank", vertex.color=randomColor(k))``

We can specify a particular hue, such as red.

``plot(erdos.renyi.game(k, 0.1), vertex.label=NA,     edge.lty="blank", vertex.color=randomColor(k, hue="red"))``

We can also get random colors with specific luminosity.

``plot(erdos.renyi.game(k, 0.1), vertex.label=NA,     edge.lty="blank", vertex.color=randomColor(k, luminosity="light"))``

We can also ask for a set of optimally distinct colors so that colors in our plot are not too similar. If we use `ggplot2` to select the color space for our states in the map below, we get many similar colors.

``library(dplyr)library(ggplot2)library(maps) states_map <- map_data("state")ggplot(states_map, aes(x=long, y=lat, group=group)) +  geom_polygon(aes(fill=region), color="black") +  guides(fill=FALSE)``

Which states are green?

Instead, let's find the most distinctive set of colors for all states.

``s <- unique(states_map\$region)df <- data.frame(region=s, newColor=distinctColorPalette(length(s)),                 stringsAsFactors=FALSE)states_map <- left_join(states_map, df, by="region")ggplot(states_map, aes(x=long, y=lat, group=group)) +  geom_polygon(fill=states_map\$newColor, color="black")``

Now, which states are green?

To install this package from the R console, type:

``devtools::install_git("https://github.com/ronammar/randomcoloR")``

# News

## randomcoloR 1.1.0

NEW FEATURES

• Alternate color space for distinct colors

• t-SNE preprocessing of color space for improved color separation

MINOR IMPROVEMENTS

• distinctColorPalette() no longer outputs a named vector, improving compatibility with ggplot2 (where color names are meaningful)

• Shrinks original color space for improved performance (especially with t-SNE and k-medoids)

# Reference manual

install.packages("randomcoloR")

1.1.0 by Ron Ammar, 2 years ago

Report a bug at https://github.com/ronammar/randomcoloR/issues

Browse source code at https://github.com/cran/randomcoloR

Authors: Ron Ammar

Documentation:   PDF Manual