convert_color: Convert colors

Description Usage Arguments Value Examples

View source: R/convert_color.R

Description

This function converts colors to an 8-digit hex format (e.g., #FFFFFFFF). It supports RGB values, with or without an alpha value, and with a maximum of 1 or 255. It also supports hex values, with or without an alpha value, and without or without a leading #.

Usage

1

Arguments

color

Color. Required, and does not have a default value. This argument can be an RGB color specified as a vector with 3 or 4 values, as in c(1, 1, 1), c(1, 1, 1, 1), c(255, 255, 255), or c(255, 255, 255, 255), or a hex color specified as a string, as in #FFFFFF, #FFFFFFFF, FFFFFF, or FFFFFFFF.

Value

This function returns a color in an 8-digit hex format with a leading # (e.g., #FFFFFFFF).

Examples

1
2
3
4
5
6
7
8
convert_color(c(1, 1, 1)) # RGB, no alpha, max 1
convert_color(c(1, 1, 1, 1)) # RGB, alpha, max 1
convert_color(c(255, 255, 255)) # RGB, no alpha, max 255
convert_color(c(255, 255, 255, 255)) # RGB, alpha, max 255
convert_color("#FFFFFF") # hex, no alpha, with #
convert_color("#FFFFFFFF") # hex, alpha, with #
convert_color("FFFFFF") # hex, no alpha, without #
convert_color("FFFFFFFF") # hex, alpha, without #

jfjelstul/eumaps documentation built on Jan. 8, 2022, 1:17 a.m.