You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Super cool package. I used it to extract hex codes for transparent values of a whole palette to use as different layers of a ggplot2, as the colours represent different levels of data (see below).
To do this I passed a colour palette in hex codes to hex_to_rgb() then used rgba_to_hex() with an alpha value to get the new colour palette. However hex_to_rgb() currently returns the string "r = X, g = Y, b = Z", when a vector of the three colours would be more useful maybe?
My code and function are here:
# set colours for plot
colours <- RColorBrewer::brewer.pal(10, 'Spectral')
# function to make points lighter but not transparent
alpha_hex <- function(hex_code, alpha = 1){
# split by ',' and extract number
temp <- monochromeR::hex_to_rgb(hex_code) %>%
str_split(., ',') %>%
.[[1]] %>%
parse_number
return(rgba_to_hex(c(temp, alpha)))
}
purrr::map_vec(colours, alpha_hex, alpha = 0.7)
The text was updated successfully, but these errors were encountered:
Hi @padpadpadpad Thank you for sharing this. I really like what you did with the colours! I'm actually in the process of collaborating with @xx02al to get the code up to speed with new developments, so happy to look into this for the next version of the package!
Hi @padpadpadpad. I recommend using the farver package for modifying colour space channels in hex-encoded colour strings. Here's an example considering what you attempted to do. Sidenote: since I am not able to reproduce your example, you might check whether you need to set value 0.3 or 0.7 in the example you provided.
Hi!
Super cool package. I used it to extract hex codes for transparent values of a whole palette to use as different layers of a ggplot2, as the colours represent different levels of data (see below).
To do this I passed a colour palette in hex codes to hex_to_rgb() then used rgba_to_hex() with an alpha value to get the new colour palette. However hex_to_rgb() currently returns the string "r = X, g = Y, b = Z", when a vector of the three colours would be more useful maybe?
My code and function are here:
The text was updated successfully, but these errors were encountered: