Skip to content

drmowinckels/colorhex

Repository files navigation

colorhex

CRAN status R-CMD-check

The goal of colorhex is to create an interface to color-hex.com, a website with hexidecimal colors and information about them.

It also has lots of user-made palettes that can be used and browsed.

Installation

You can install the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("drmowinckels/colorhex", ref = "main")

Example

Single colors

library(colorhex)

x <- get_color("#470f0f")
x
#> # Color-hex: #470f0f
#> RGB: 71, 15, 15
#> HSL: 0.00, 0.65, 0.17
#> CMYK: 0.00, 0.79, 0.79   0.72
#> triadic: #0f470f, #0f0f47
#> complementary: #0f4747
#> used in 2 palettes
plot(x)

x <- get_popular_colors()
x
#>  [1] "#ff80ed" "#065535" "#000000" "#133337" "#ffc0cb" "#ffffff" "#ffe4e1"
#>  [8] "#008080" "#ff0000" "#e6e6fa" "#ffd700" "#00ffff" "#ffa500" "#0000ff"
#> [15] "#ff7373" "#c6e2ff" "#40e0d0" "#b0e0e6" "#d3ffce" "#f0f8ff" "#666666"
#> [22] "#faebd7" "#bada55" "#fa8072" "#003366" "#ffb6c1" "#c0c0c0" "#ffff00"
#> [29] "#800000" "#800080" "#c39797" "#00ff00" "#7fffd4" "#fff68f" "#eeeeee"
#> [36] "#cccccc" "#f08080" "#20b2aa" "#ffc3a0" "#333333" "#66cdaa" "#c0d6e4"
#> [43] "#ff6666" "#ff00ff" "#cbbeb5" "#ffdab9" "#468499" "#ff7f50" "#afeeee"
#> [50] "#b4eeb4" "#00ced1" "#008000" "#660066" "#f6546a" "#0e2f44" "#b6fcd5"
#> [57] "#990000" "#696969" "#f5f5f5" "#daa520" "#000080" "#6897bb" "#808080"
#> [64] "#f5f5dc" "#088da5" "#8b0000" "#8a2be2" "#81d8d0" "#ccff00" "#ffff66"
#> [71] "#ff4040" "#dddddd" "#2acaea" "#101010" "#0a75ad" "#ff1493" "#420420"
#> [78] "#66cccc" "#a0db8e" "#999999" "#794044" "#3399ff" "#cc0000" "#00ff7f"
scales::show_col(x)

Palettes

latest <- get_latest_palettes()
plot(latest)

popular <- get_popular_palettes()
plot(popular)

ggplot2 scales

library(ggplot2)

ggplot(mtcars, aes(mpg)) +
   geom_density(aes(fill = disp, group = disp)) +
   scale_fill_palettehex_c(popular)

ggplot(mtcars, aes(mpg)) +
  geom_density(aes(fill = disp, group = disp)) +
  scale_fill_palettehex_c(popular, 3)

ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) +
   geom_point() +
   scale_color_palettehex_d(popular)

ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) +
   geom_point() +
   scale_color_palettehex_d(popular, 1872)

x <- get_color("#008080")

ggplot(mtcars, aes(mpg)) +
   geom_density(aes(fill = disp, group = disp)) +
   scale_fill_colorhex_c(x)

ggplot(mtcars, aes(mpg)) +
  geom_density(aes(fill = disp, group = disp)) +
  scale_fill_colorhex_c(x, "tints")

ggplot(mtcars, aes(mpg)) +
  geom_density(aes(fill = disp, group = disp)) +
  scale_fill_colorhex_c(x, "shades")

ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) +
   geom_point() +
   scale_color_colorhex_d(x, "triadic")

ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) +
   geom_point() +
   scale_color_colorhex_d(x, "shades")