Written and maintained by CASRAI Editorial Board
Published
On this page
RColorBrewer is an R package that gives you ready-made colour palettes based on Cynthia Brewer’s ColorBrewer scheme, designed for maps and other graphics. The function you will use most is brewer.pal(n, name), which returns n colours from a named palette. The current CRAN release is 1.1-3 (published 2022-04-03), licensed under Apache License 2.0.
Ask CASRAI · free to tryQuestion about this guide? Ask CASRAI answers with linked sources. 2 free questions a day, no account.
What RColorBrewer is used for in research
Researchers use it to pick colours that suit the kind of variable being plotted: ordered values (sequential), values that diverge from a midpoint (diverging), or unordered categories (qualitative). The package documentation describes the three types this way: sequential palettes suit ordered data running from light (low) to dark (high); diverging palettes emphasise a middle value with light colours and both extremes with dark, contrasting hues; qualitative palettes suit nominal or categorical data. Choosing the type before the palette is the main decision. For the design side of figures, see scientific figure rules for journal submission.
Install or access
Install from CRAN, then load the package in each session:
install.packages("RColorBrewer") library(RColorBrewer)
The CRAN page lists the package as requiring R (>= 2.0.0). If you work in RStudio, see how to use RStudio for the console and package panes. The palettes can also be previewed without R at colorbrewer2.org, the ColorBrewer web tool (copyright Cynthia Brewer, Mark Harrower and The Pennsylvania State University), which offers filters for colourblind-safe, print-friendly and photocopy-safe schemes and exports HEX, RGB and CMYK values.
Step-by-step: choose and use a palette
- Decide the variable type. Ordered values: sequential. Values around a meaningful midpoint: diverging. Unordered groups: qualitative.
- See the options. Run
display.brewer.all()to draw every palette. Narrow it with thetypeargument ("seq","div","qual"or"all"), withselect(a list of palette names), withexact.n=TRUEto show only palettes that support exactlyncolours, or withcolorblindFriendly=TRUEto show only colourblind-friendly palettes. For example:display.brewer.all(type="div", colorblindFriendly=TRUE). - Preview one palette.
display.brewer.pal(7, "BrBG")draws seven colours from the BrBG diverging palette. - Get the colour codes.
brewer.pal(7, "Greens")returns seven hexadecimal colour strings from the sequential Greens palette. - Apply them to a plot. Pass the vector to the
colargument of a base graphics function, or to a ggplot2 manual scale. Example with base graphics:barplot(1:7, col = brewer.pal(7, "Greens")).
Check how many colours a palette supports
brewer.pal.info is a data frame (a variable, not a function) with information about the available palettes. The package’s own example reads the maximum for one palette with brewer.pal.info["Blues",]$maxcolors. Use it to look up a limit before you ask for n colours.
Palettes and their limits
The minimum n is 3 for every palette; the maximum depends on the palette (source: the package help page, ColorBrewer).
| Type | Use for | Palettes | Colours available |
|---|---|---|---|
| Sequential | Ordered data, light to dark | Blues, BuGn, BuPu, GnBu, Greens, Greys, Oranges, OrRd, PuBu, PuBuGn, PuRd, Purples, RdPu, Reds, YlGn, YlGnBu, YlOrBr, YlOrRd | 3 to 9 |
| Diverging | Data with a meaningful midpoint | BrBG, PiYG, PRGn, PuOr, RdBu, RdGy, RdYlBu, RdYlGn, Spectral | 3 to 11 |
| Qualitative | Nominal or categorical data | Accent, Dark2, Paired, Pastel1, Pastel2, Set1, Set2, Set3 | Max: Accent 8, Dark2 8, Paired 12, Pastel1 9, Pastel2 8, Set1 9, Set2 8, Set3 12 |
Output and how to read it
brewer.pal() returns a character vector of hex codes, for example a string beginning with # for each colour. Order matters: in sequential and diverging palettes the vector runs along the scale, so map the first colour to your lowest category or value. In qualitative palettes the order carries no meaning. display.brewer.pal() and display.brewer.all() produce graphics-window swatches rather than a return value you analyse.
Troubleshooting
- Error after naming a palette. A palette name that does not exist produces an error. Copy the names exactly as listed in the table above.
- Warning about the number of colours. Asking for more colours than the palette supports produces a warning. Look up the limit in
brewer.pal.infoor the table above, and note thatnbelow 3 is also outside the supported range. - More groups than a palette allows. Base R’s
colorRampPalette(colors, ...)returns a function that interpolates between colours you give it, and its help page names the sequential and diverging ColorBrewer palettes as good starting points for interpolation. Example:colorRampPalette(brewer.pal(9, "Blues"))(20)returns 20 colours. Interpolated colours are no longer the original discrete ColorBrewer classes, so say so if you report them in a methods section.
Where it connects to other plotting tools
For ggplot2 scales that use the same palettes, see ggplot colour scales. For matrix heatmaps with annotation, see ComplexHeatmap. For choosing colours in RStudio generally, see RStudio colours.
Free alternatives
| Option | What it is | Source |
|---|---|---|
hcl.colors(n, palette = "viridis") |
Base R (grDevices) function that returns n colours from perceptually based HCL palettes in qualitative, sequential, diverging and divergingx families; the default palette is viridis. hcl.pals() lists the names. |
R grDevices documentation |
colorRampPalette() |
Base R function for interpolating between colours you supply, including ColorBrewer ones. | R grDevices documentation |
| colorbrewer2.org | Web tool for the same ColorBrewer schemes, with colourblind-safe, print-friendly and photocopy-safe filters. | colorbrewer2.org |
FAQ
What does the brewer.pal function do?
brewer.pal(n, name) returns a vector of n colours from the named ColorBrewer palette. n must be at least 3, and the maximum depends on the palette.
Is brewer.pal.info a function?
No. It is a data frame holding information about the available palettes, accessed without parentheses.
How do I show only colourblind-friendly palettes?
Call display.brewer.all(colorblindFriendly=TRUE). This is the only colourblind-related option in the package help page.
Do I need to cite RColorBrewer or ColorBrewer?
The package help page says the ColorBrewer designers ask users to cite the project if they use the schemes, and points to colorbrewer.org for more information.
Sources
- CRAN, RColorBrewer package page (version 1.1-3, published 2022-04-03; Apache License 2.0), read 2026-11-08: cran.r-project.org/web/packages/RColorBrewer
- RColorBrewer reference manual, ColorBrewer help page, read 2026-11-08: CRAN reference manual
- ColorBrewer, colorbrewer2.org, read 2026-11-08: colorbrewer2.org
- R documentation, grDevices colorRamp and palettes pages, read 2026-11-08: colorRamp, hcl.colors







