Written and maintained by CASRAI Editorial Board
Published · Last updated
On this page
“RStudio colours” means two different things: the colours R draws in plots (set with R’s own graphics functions, which RStudio simply displays) and the colours of the RStudio editor itself (a theme). The first is controlled by code, the second by a menu: Tools > Global Options > Appearance. This guide covers both, with the commands exactly as the official documentation gives them. The American spelling, “RStudio colors”, is the same topic, and R accepts both colors() and colours().
What it is used for in research
In a manuscript or thesis, colour in an R figure is a reporting choice: the same named colour or palette has to be reproducible from the script. R accepts a colour as a name, a hex string, or a positive integer that points into the current palette. For choosing scales inside ggplot2 (Brewer, viridis, manual), see ggplot colour palettes; this page covers base R and the RStudio editor, and does not repeat that material.
Install or access (official source only)
Colour functions such as colors(), col2rgb() and palette() belong to the grDevices package, which is part of R, so no extra package is needed. RStudio is the IDE from Posit; its theme settings are documented in the RStudio User Guide (docs.posit.co). Custom editor themes use the rstudioapi package.
Step-by-step: list, inspect and set colours
1. List the built-in colour names
- Run
colors()(orcolours()). The documented usage iscolors(distinct = FALSE), and the value is a character vector of all built-in colour names. - Run
colors(distinct = TRUE)to return only colours that are distinct from one another. R’s colors() reference page gives 657 named colours, of which 502 are distinct. - Use any returned name in a
col=argument of a graphics function, for exampleplot(1:10, col = "steelblue"). The name “transparent” is not in the list but is accepted as a colour specification.
2. Convert a colour to RGB numbers
Use col2rgb(col, alpha = FALSE). The col argument may be a vector of any of the three kinds of R colour specification: a name, a hex string, or a positive integer i meaning palette()[i]. The result is an integer matrix with three rows (four if alpha = TRUE, adding opacity) and one column per colour. For example, col2rgb("steelblue") returns one column of three red, green and blue values.
3. Use a predefined palette
- Run
palette.pals()to list the predefined palettes. - Run
palette.colors(n = NULL, palette = "Okabe-Ito")to select colours from one. “Okabe-Ito” is the default palette ofpalette.colors(); “Tableau 10” and “Alphabet” are also named in the documentation. - Set the palette that integer colours index into with
palette(value), for examplepalette(hcl.colors(8, "viridis")), which is the pattern the official example uses. Pass “default” topalette()to go back to the default.
4. Change the RStudio editor theme
- Open Tools > Global Options > Appearance.
- Pick one from the Editor theme selector. The Posit documentation names Ambiance, Chaos, Chrome and Xcode among the included themes.
- For a theme that is not listed, RStudio supports custom editor themes in two formats, tmTheme and rstheme. To add an rstheme, use
rstudioapi::addTheme(themePath, apply, force, globally). To add a tmTheme, userstudioapi::convertTheme(themePath, add, outputLocation, apply, force, globally), which returns the name of the newly added theme.
Output and how to read it
- colors() prints a plain character vector of names; it contains no hex or RGB values.
- col2rgb() prints a matrix: one column per colour you passed in, one row each for red, green and blue (plus alpha when requested).
- palette.pals() prints palette names; palette.colors() returns colours from the one you choose.
Test a figure with a colour-vision-deficiency simulator before describing any palette as accessible in a methods section.
Troubleshooting
- A colour name is rejected. Check it against
colors(); only names in that vector (plus “transparent”) are valid names. - Integer colours look different after a palette change. An integer i means
palette()[i], so changing the palette changes every colour specified by number. Callpalette("default")to reset. - The editor theme did not change. The theme selector lives under Tools > Global Options > Appearance, and it changes the editor only, not the colours inside your plots.
Free alternatives: other ways to specify a colour in R
| Specification | What it is | Source function |
|---|---|---|
| Colour name | An entry from the built-in names | colors() |
| Hex string | One of the three colour specification kinds accepted by col2rgb() |
col2rgb() |
| Positive integer | Index i into palette() |
palette() |
| Predefined palette | Colours selected from a named palette such as “Okabe-Ito” | palette.colors() |
All four are part of base R and free to use. For related plotting tasks see heatmaps in R and scatterplots in R; for the Python equivalent see Seaborn colour palettes.
FAQ
How many colours does R have?
The R reference page’s example comments give 657 named colours, 502 of them distinct when you call colors(distinct = TRUE).
How do I see the RGB values of an R colour?
Use col2rgb(), for example col2rgb("steelblue"), and add alpha = TRUE for opacity.
How do I change the RStudio theme?
Go to Tools > Global Options > Appearance and choose from the Editor theme selector; custom themes are added with rstudioapi.
Is it RStudio colours or RStudio colors?
Same topic. R provides both colors() and colours(), and they return the same built-in names.
Related: Quarto vs R Markdown if your coloured figures end up in a report.
Sources (official docs)
- R documentation: colors {grDevices}, checked 2026-10-29
- R documentation: col2rgb {grDevices}, checked 2026-10-29
- R documentation: palette {grDevices}, checked 2026-10-29
- Themes, RStudio User Guide (Posit), checked 2026-10-29







