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(132,212,102,100)" "rgba(215,7,55,100)"    "rgba(183,119,106,100)"
#> [4] "rgba(61,205,170,100)"  "rgba(139,207,129,100)"
hexcolor2rgba(colors, alpha = .5)
#> [1] "rgba(132,212,102,50)" "rgba(215,7,55,50)"    "rgba(183,119,106,50)"
#> [4] "rgba(61,205,170,50)"  "rgba(139,207,129,50)"
colors <- gsub('FF$', 75, colors)
hexcolor2rgba(colors)
#> [1] "rgba(132,212,102,45.8823529411765)" "rgba(215,7,55,45.8823529411765)"   
#> [3] "rgba(183,119,106,45.8823529411765)" "rgba(61,205,170,45.8823529411765)" 
#> [5] "rgba(139,207,129,45.8823529411765)"
hexcolor2rgba(colors, alpha = .5)
#> [1] "rgba(132,212,102,50)" "rgba(215,7,55,50)"    "rgba(183,119,106,50)"
#> [4] "rgba(61,205,170,50)"  "rgba(139,207,129,50)"