Learn R Programming

col2hex2col (version 0.3.1)

get_color_data: Get Color Database

Description

Returns the complete color database as a data frame containing all 32,000+ color names and their corresponding hexadecimal codes.

Usage

get_color_data()

Arguments

Value

A data frame with two columns:

name

Character vector of color names (lowercase)

hex

Character vector of hexadecimal color codes (uppercase, format: #RRGGBB)

The data frame contains 32,462 rows representing all available colors, including both R's 657 built-in colors and the extended color-names database.

Details

The returned data frame is sorted alphabetically by color name. Each color name maps to exactly one hex code, though multiple color names may share the same hex code.

This function is useful for:

  • Exploring available color names

  • Creating custom color palettes

  • Searching for colors by name pattern

  • Analyzing color distributions

  • Building color visualization tools

See Also

color_to_hex for converting specific color names to hex codes, hex_to_color for the reverse conversion, create_color_table for creating visual color tables

Examples

Run this code
# Get the complete color database
colors_df <- get_color_data()
head(colors_df)

# See dimensions
dim(colors_df)

# Find all colors containing "blue"
blue_colors <- colors_df[grepl("blue", colors_df$name), ]
head(blue_colors)

# Get a random sample of colors
set.seed(123)
sample_colors <- colors_df[sample(nrow(colors_df), 10), ]
sample_colors

Run the code above in your browser using DataLab