I know that R is loaded with some color palettes automatically, such as palette, rainbow , heat.colors and gray. I’m also aware of RColorBrewer. But, what if I want to use a custom color palette and assign colors by name? Is that possible?
My company’s color palette is as follows:
#1A73BA (R: 26 G: 115 B: 186) - this is a blue
#FFDB43 (R:255 G:219 B:67) - this is a yellow
#B54B05 (R:181 G:75 B:5) - this is an orange
My company’s initials are AT.
I’d like to be able to call those colors via a name rather than by the HEX or RGB because I don’t remember them. Ideally, I could create a file that would load into R automatically that would initiate these colors.
ATBlue <- #1A73BA
ATYellow <- #FFDB43
ATOrange <- #B54B05
Then, I could call the colors:
plot(x,y, col = "ATBlue")
I could put the values into a dataframe, then call them like so:
ATColors <- data.frame(name = c("ATBlue", "ATYellow", "ATOrange"), color= c("#1A73BA", "#F7D364", "#B54B05"))
plot(x,y, col = ATColors[3,2])
But I would need to know the location in the dataframe in order to call it correctly.
Can I create an element that will automatically load when R launches that would allow me call a custom color name into a plot?
This answers (or at least is one possible answer to) your comments and edits:
The definition method with rgb allows you to set an alpha level , thus allowing transparency on graphic devices that support it (at a minimum: ‘pdf’, ‘windows’, ‘quartz’ and ‘X11’).
You can also name a ‘palette-vector’
That vector could be accessed with either numbers or names:
In general I think you will find that if you use all lower case there will be good correspondence for the base and graphics packages (loaded by default so no renaming will be necessary) with that gif-list. So it’s already part of R. Let’s say you wanted to find the R color name of “LavenderBlush”. The vector of assigned color names is returned from colors() but it’s rather big, so you can whittle it down with:
And say you wanted to see whether the Hex code for that color were the same as the one on your unreadable gif table:
Yep. And for your example just use “seagreen”:
If you have a hex-code value you can append “#” to it with
paste0:If you have a vector of such values,
paste0is also vectorized: