Created
January 8, 2018 15:05
-
-
Save chasemc/4d5ba92e22f132708f4ee3a987caaf6c to your computer and use it in GitHub Desktop.
Convert a vector of named colors to HEX values in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cols is a vector of named colors | |
# First we convert the named colors to rgb, and store the values in a list | |
rgbVals<-lapply(cols,col2rgb) | |
# Then convert the list to a data frame and flip it | |
rgbVals<-t(as.data.frame(rgbVals,col.names = seq(1,length(rgbVals),by=1))) | |
# Then we convert the rgb values to HEX | |
hexVal<-sapply(1:length(rgbVal[,1]),function(x){ rgb(rgbVal[x,"red"],rgbVal[x,"green"],rgbVal[x,"blue"],maxColorValue = 255) }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment