Hex code colors to rgba format

hexcolor2rgba(hexcolors, alpha = NULL)

Arguments

hexcolors

character (vector), hexcode colors (e.g. #FFFFFF)

alpha

numeric in range [0-1], default: NULL to use full opacity or given opacity (AA) in hexcolors (#RRGGBBAA)

Value

colors in rgba format

Examples

colors <- colorify(5)
#> 5 colors generated
hexcolor2rgba(colors)
#> [1] "rgba(2,197,64,100)"    "rgba(226,149,234,100)" "rgba(254,161,221,100)"
#> [4] "rgba(127,218,63,100)"  "rgba(91,144,102,100)" 
hexcolor2rgba(colors, alpha = .5)
#> [1] "rgba(2,197,64,50)"    "rgba(226,149,234,50)" "rgba(254,161,221,50)"
#> [4] "rgba(127,218,63,50)"  "rgba(91,144,102,50)" 
colors <- gsub('FF$', 75, colors)
hexcolor2rgba(colors)
#> [1] "rgba(2,197,64,45.8823529411765)"    "rgba(226,149,234,45.8823529411765)"
#> [3] "rgba(254,161,221,45.8823529411765)" "rgba(127,218,63,45.8823529411765)" 
#> [5] "rgba(91,144,102,45.8823529411765)" 
hexcolor2rgba(colors, alpha = .5)
#> [1] "rgba(2,197,64,50)"    "rgba(226,149,234,50)" "rgba(254,161,221,50)"
#> [4] "rgba(127,218,63,50)"  "rgba(91,144,102,50)"