Skip to main content
v2026.11,986 entries · CC-BY 4.0

RColorBrewer in R: Install, brewer.pal() and Palettes

RColorBrewer in R: install it, call brewer.pal(), pick sequential, diverging or qualitative palettes, and check each palette’s colour limit.

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.

Ask your first question freeSubscribe

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

  1. Decide the variable type. Ordered values: sequential. Values around a meaningful midpoint: diverging. Unordered groups: qualitative.
  2. See the options. Run display.brewer.all() to draw every palette. Narrow it with the type argument ("seq", "div", "qual" or "all"), with select (a list of palette names), with exact.n=TRUE to show only palettes that support exactly n colours, or with colorblindFriendly=TRUE to show only colourblind-friendly palettes. For example: display.brewer.all(type="div", colorblindFriendly=TRUE).
  3. Preview one palette. display.brewer.pal(7, "BrBG") draws seven colours from the BrBG diverging palette.
  4. Get the colour codes. brewer.pal(7, "Greens") returns seven hexadecimal colour strings from the sequential Greens palette.
  5. Apply them to a plot. Pass the vector to the col argument 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.info or the table above, and note that n below 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

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about RColorBrewer in R: Install, brewer.pal() and Palettes

2 free questions a day, no account.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →