The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

col2hex2col col2hex2col logo

R-CMD-check CRAN status Lifecycle: stable

Overview

col2hex2col provides fast and simple functions to convert between color names and hexadecimal color codes. The package now supports an extensive database of over 32,000 color names, including all 657 R built-in colors plus the comprehensive color-names database.

The name is a playful reference to “2 Fast 2 Furious” - because color conversion should be both fun and fast!

Installation

You can install the development version from GitHub:

# install.packages("devtools")
devtools::install_github("AnttiRask/col2hex2col")

Usage

Convert color names to hex codes

library(col2hex2col)

# Single color
color_to_hex("red")
#> [1] "#FF0000"

# Multiple colors
color_to_hex(c("red", "blue", "green"))
#> [1] "#FF0000" "#0000FF" "#00FF00"

# Works with all 657 R color names
color_to_hex(c("skyblue", "coral", "chartreuse"))
#> [1] "#87CEEB" "#FF7F50" "#7FFF00"

# Also works with 32,000+ extended color names!
color_to_hex(c("sunset orange", "arctic ocean"))
#> [1] "#FD5E53" "#66C3D0"

Convert hex codes to color names

# Single hex code
hex_to_color("#FF0000")
#> [1] "red"

# Multiple hex codes
hex_to_color(c("#FF0000", "#0000FF", "#00FF00"))
#> [1] "red"   "blue"  "green"

# Case insensitive
hex_to_color("#ff0000")
#> [1] "red"

Round-trip conversion

# Color -> Hex -> Color
colors <- c("red", "blue", "green")
hex_codes <- color_to_hex(colors)
hex_to_color(hex_codes)
#> [1] "red"   "blue"  "green"

Explore and visualize the color database

# Get all 32,462 colors as a data frame
colors_df <- get_color_data()
head(colors_df)
#>           name     hex
#> 1    aaron blue #6FC6E0
#> 2 abbey purple #73607C
#> 3   aberdonian #4D6767
#> 4    aborigine #A99B85
#> 5    aboukir   #8BA58F
#> 6    abraxas   #5B6E91

# Find specific colors
blue_colors <- colors_df[grepl("blue", colors_df$name), ]
nrow(blue_colors)
#> [1] 1517

# Create a beautiful color swatch table (requires gt package)
create_color_table(head(colors_df, 9))
Color Table Example

The create_color_table() function creates an interactive table with visual color swatches, making it easy to explore and select colors for your projects.

Features

Why col2hex2col?

Acknowledgments

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

License

MIT © Antti Rask

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.