# Convert a single color
color_to_hex("red")
# Convert multiple colors
color_to_hex(c("red", "blue", "green"))
# Works with all R color names
color_to_hex(c("skyblue", "coral", "chartreuse"))
# Also works with extended color names
color_to_hex(c("sunset orange", "arctic ocean", "forest green"))
# Case insensitive
color_to_hex(c("Red", "BLUE", "Green"))
# Use in a data visualization context
colors <- c("steelblue", "firebrick", "forestgreen")
hex_codes <- color_to_hex(colors)
# hex_codes can now be used with plotting functions
Run the code above in your browser using DataLab