Learn R Programming

evanverse (version 0.4.0)

rgb2hex: Convert RGB values to HEX color codes

Description

Convert an RGB triplet (or a list of triplets) to HEX color codes.

Usage

rgb2hex(rgb)

Value

A HEX color string if a single RGB vector is provided, or a character vector of HEX codes if a list is provided.

Arguments

rgb

A numeric vector of length 3 (e.g., c(255, 128, 0)), or a list of such vectors (e.g., list(c(255,128,0), c(0,255,0))).

Examples

Run this code
rgb2hex(c(255, 128, 0))                           # "#FF8000"
rgb2hex(list(c(255,128,0), c(0,255,0)))           # c("#FF8000", "#00FF00")

Run the code above in your browser using DataLab