Take the 2-minute tour ×

I have a few colors (rgb/hex codes) that I would like to be available as defaults. I would like for the colors to be available on startup, without having to run any scripts. In other words, I would like to run the command colors() and have my custom colors show up in the list.

I suspect this list is populated from some file in the R tree, or from some other config file somewhere else. Specifically:

  • What file does R pull the color definitions from?

Relevant data:

> version
platform       x86_64-apple-darwin9.8.0     
arch           x86_64                       
os             darwin9.8.0                  
system         x86_64, darwin9.8.0          
major          2                            
minor          15.1                         
year           2012                         
month          06                           
day            22                           
svn rev        59600                        
language       R                            
version.string R version 2.15.1 (2012-06-22)
nickname       Roasted Marshmallows
share|improve this question
Are you talking about the colors used for the R IDE (e.g in the interactive windows, the editor windows etc.) or the ones which various plotting functions use by default ? –  mjv Nov 9 '12 at 16:44
Nothing is impossible, but I wouldn't attempt to change the output of colors(). Typically for something like this you might just drop the hex codes in your .RProfile file. (And there is no "color config file", FYI.) –  joran Nov 9 '12 at 16:47
mjv: I just want to add to the list of colors so I don't have to define them every time. –  BenDundee Nov 14 '12 at 15:48
joran: Thanks--I blindly assumed it was pulling color defs from a config file. But as Josh points out below, I think I'd have to do some compiling, which is a bit beyond the amount of effort I'm willing to expend. –  BenDundee Nov 14 '12 at 15:49

2 Answers 2

up vote 3 down vote accepted

You can (if you really want), change the default palette to your own colours. For example,

(palette(c("yellow", "orange")))
plot(1:10, col=1:10)

Rather than providing named colours, you could also specify rgb colours using the rgb function. You can add this command to your .Rprofile so it's available on start-up.

However, a better idea would be to define your own palette:

#Put this in your .Rprofile
mycols = adjustcolor(palette(), alpha.f = 0.3)

That way you don't over-ride the default. See ?palette for other examples.

share|improve this answer
I'm not really looking for a whole palette, I just want to be able to say col=MyOwnPersonalBlue. –  BenDundee Nov 9 '12 at 21:45
@BenDundee -- Sounds like you just want to do something like this: MyOwnPersonalBlue <- "#00008B"; plot(rnorm(10), col=MyOwnPersonalBlue, pch=16). (You can then, if you'd like, store MyOwnPersonalBlue in your .Rprofile, for more details on which see ?Startup.) –  Josh O'Brien Nov 14 '12 at 16:36
@JoshO'Brien: Thanks, I think this is exactly what i need. –  BenDundee Nov 29 '12 at 14:49

To directly answer your bulleted question: R's color database is stored in the "colors.c" source file.

Because colors() etc. access compiled versions of that database, you can't add to the named colors without editing the source code and then recompiling R.

Here are the first few lines defining the ColorDataBase in $R_SOURCE_HOME/src/main/colors.c:

static ColorDataBaseEntry ColorDataBase[] = {
    /* name rgb code -- filled in by InitColors() */
    {"white",   "#FFFFFF",  0},
    {"aliceblue",   "#F0F8FF",  0},
    {"antiquewhite",    "#FAEBD7",  0},
    {"antiquewhite1",   "#FFEFDB",  0},
    {"antiquewhite2",   "#EEDFCC",  0},
share|improve this answer
And, to borrow from some old car ads, if you're thinking about modifying this file: "Not that you would, but you could." –  Carl Witthoft Nov 9 '12 at 17:47
This sounds tempting... But I don't think recompiling R is what I want to do. I'd up vote this response, but I don't have the street cred yet :) –  BenDundee Nov 14 '12 at 15:47
@BenDundee -- Yes ... just say no to that temptation! Much better to do something like what I mentioned in my comment to cgillespie's answer. Cheers. –  Josh O'Brien Nov 14 '12 at 16:38

Your Answer


