Package 'colorhex'

Title: Colors and Palettes from Color-Hex
Description: The website <https://www.color-hex.com> is a great resource of hex colour codes and palettes. This package allows you to retrieve palettes and colour information from the website directly from R. There are also custom scale-functions for 'ggplot2'.
Authors: Athanasia Mo Mowinckel [aut, cre] , Julia Romanowska [ctb]
Maintainer: Athanasia Mo Mowinckel <[email protected]>
License: MIT + file LICENSE
Version: 0.1.4
Built: 2024-11-09 03:52:28 UTC
Source: https://github.com/drmowinckels/colorhex

Help Index


Get color information

Description

Get color information from www.color-hex.com of a hex-color.

Usage

get_color(hex)

Arguments

hex

character string that is a hexidecimal color

Value

list of class 'colorhex'

Examples

if(curl::has_internet()){
get_color("#470f0f")
}

Get latest palettes

Description

Retrieve the most recently made palettes from www.color-hex.com

Usage

get_latest_palettes()

Value

data.frame with name, id and colours

Examples

if(curl::has_internet()){
get_latest_palettes()
}

Get palettes from id

Description

Get palette information from www.color-hex.com based on the palette id (can be found in the url)

Usage

get_palette(id)

Arguments

id

numeric id of a palette

Value

data.frame with palette information

Examples

if(curl::has_internet()){
get_palette(103107)

# Lookup multiple palettes
id <- c(103161, 103107)
get_palette(id)
}

Generate random HEX colour

Description

Generate random HEX colour

Usage

get_random_color()

Value

character hex value

Examples

get_random_color()

Validate Hex

Description

validate if string is hexidecimal color code

Usage

is_hex(x)

Arguments

x

hexidecimal character

Value

logical. TRUE if object is a hexidecimal code


Colour scales for ggplot2

Description

Colour and fill scales for ggplot2 plots, using object of class colorhex as basis for colour choices.

Usage

scale_colour_colorhex_d(x, type = "triadic", reverse = FALSE, ...)

scale_color_colorhex_d(x, type = "triadic", reverse = FALSE, ...)

scale_fill_colorhex_d(x, type = "triadic", reverse = FALSE, ...)

scale_colour_colorhex_c(x, type = "complementary", reverse = FALSE, ...)

scale_color_colorhex_c(x, type = "complementary", reverse = FALSE, ...)

scale_fill_colorhex_c(x, type = "complementary", reverse = FALSE, ...)

Arguments

x

object of class colorhex

type

character. Type of colours to use. One of c("complementary", "triadic" (default), "shades", "tints", "related")

reverse

logical. If scale should b reversed (default: FALSE)

...

arguments to be passed to discrete_scale

Details

The colorhex class is a list where there is a variety of extra information on the hex colour selected. This information can be used to create colour scales to be used in ggplot2.

Value

a ggplot2-proto

Functions

  • scale_colour_colorhex_d(): Discrete colour scale

  • scale_color_colorhex_d(): Discrete colour scale

  • scale_fill_colorhex_d(): Discrete fill scale

  • scale_colour_colorhex_c(): Continuous colour scale

  • scale_color_colorhex_c(): Continuous colour scale

  • scale_fill_colorhex_c(): Continuous fill scale

Examples

if(curl::has_internet()){
library(ggplot2)

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")
 }

Colour scales for ggplot2

Description

Colour and fill scales for ggplot2 plots, using object of class palettehex.

Usage

scale_colour_palettehex_d(x, which = 1, reverse = FALSE, ...)

scale_color_palettehex_d(x, which = 1, reverse = FALSE, ...)

scale_fill_palettehex_d(x, which = 1, reverse = FALSE, ...)

scale_colour_palettehex_c(x, which = 1, reverse = FALSE, ...)

scale_color_palettehex_c(x, which = 1, reverse = FALSE, ...)

scale_fill_palettehex_c(x, which = 1, reverse = FALSE, ...)

Arguments

x

object of class palettehex

which

selection of which palette of a set to choose. Either by name, id or numeric index.

reverse

logical. If scale should b reversed (default: FALSE)

...

arguments to be passed to discrete_scale

Details

The palettehex class is a data.frame of many palettes. This function takes such a data.frame and a choice of palette by name, id or numeric index can be made for the scale.

Value

ggplot2-proto

Functions

  • scale_colour_palettehex_d(): Discrete colour scale

  • scale_color_palettehex_d(): Discrete colour scale

  • scale_fill_palettehex_d(): Discrete fill scale

  • scale_colour_palettehex_c(): Continuous colour scale

  • scale_color_palettehex_c(): Continuous colour scale

  • scale_fill_palettehex_c(): Continuous fill scale

Examples

if(curl::has_internet()){
library(ggplot2)

x <- get_popular_palettes()

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

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

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

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