R Color Code Reference: 20 Popular Palettes and How to Apply ThemColor is one of the most powerful tools in data visualization: it directs attention, encodes information, and improves readability when used thoughtfully. R provides multiple ways to specify and apply colors — named colors, hex codes, RGB/HSV values, and complete palettes from base R, the RColorBrewer package, viridis, and many others. This article is a comprehensive reference to 20 popular color palettes in R, why and when to use each, and concrete examples showing how to apply them in base graphics, ggplot2, and other common plotting workflows.
Why palettes matter
Good palettes:
- Improve clarity and interpretability.
- Support colorblind and grayscale viewing.
- Maintain consistent aesthetics across figures and publications.
Choose palettes based on:
- Data type — categorical (qualitative), sequential (ordered, single-hue), or diverging (centered around a midpoint).
- Accessibility — check for color vision deficiencies and contrast.
- Context — presentation, print, or web.
Palette list overview
Below are 20 widely used palettes in R. Each entry includes: palette type (qualitative, sequential, diverging), source, typical use cases, example code (base R and ggplot2), and notes on accessibility.
- RColorBrewer — “Set1” (Qualitative)
- Use: distinct categorical groups (up to ~9).
- Good for: categorical labels with high contrast.
- Example (ggplot2):
library(RColorBrewer) scale_color_brewer(palette = "Set1")
- Note: bright colors; not ideal for large numbers of categories.
- RColorBrewer — “Dark2” (Qualitative)
- Use: softer than Set1, works well in print.
- Example:
scale_fill_brewer(palette = "Dark2")
- RColorBrewer — “Paired” (Qualitative)
- Use: paired categories or groups (12 colors).
- Example:
scale_color_brewer(palette = "Paired")
- RColorBrewer — “Blues” (Sequential)
- Use: single-hue sequences for ordered data.
- Example:
scale_fill_distiller(palette = "Blues", direction = 1)
- RColorBrewer — “YlGnBu” (Sequential)
- Use: choropleth maps, heatmaps.
- Example:
scale_fill_distiller(palette = "YlGnBu")
- RColorBrewer — “RdYlBu” (Diverging)
- Use: values diverging around a central midpoint (e.g., anomalies).
- Example:
scale_fill_distiller(palette = "RdYlBu", direction = -1)
- viridis — “viridis” (Sequential, perceptually uniform)
- Use: continuous data; excellent for accessibility and printing in grayscale.
- Example:
library(viridis) scale_fill_viridis_c(option = "viridis")
- Note: colorblind-friendly and perceptually uniform.
- viridis — “magma” (Sequential)
- Use: dramatic dark-to-bright transitions; good for high-contrast displays.
- Example:
scale_fill_viridis_c(option = "magma")
- viridis — “plasma” (Sequential)
- Use: vivid sequential palette with high chroma.
- Example:
scale_fill_viridis_c(option = "plasma")
- viridis — “inferno” (Sequential)
- Use: high dynamic range, legible in black-and-white reproduction.
- Example:
scale_fill_viridis_c(option = "inferno")
- wesanderson — “GrandBudapest1” (Qualitative)
- Use: stylized, thematic palettes from Wes Anderson movies.
- Example:
library(wesanderson) scale_color_manual(values = wes_palette("GrandBudapest1"))
- Note: good for stylistic plots but check for accessibility.
- ggsci — “npg” (Qualitative)
- Use: Nature Publishing Group-like palettes for publication.
- Example:
library(ggsci) scale_color_npg()
- ggthemes — “Solarized” (Qualitative/Sequential variants)
- Use: compatibility with Solarized theme aesthetics.
- Example:
library(ggthemes) scale_colour_solarized()
- colorRampPalette — custom gradient (Sequential)
- Use: create smooth transitions between any two or more colors.
- Example:
myPal <- colorRampPalette(c("#FF0000", "#FFFFFF", "#0000FF")) image(matrix(1:100,10), col = myPal(100))
- colorspace — “Heat_hcl” (Sequential, perceptually-based)
- Use: HCL-based palettes with good perceptual properties.
- Example:
library(colorspace) scale_fill_continuous_sequential(palette = "Heat_hcl")
- RColorBrewer — “Spectral” (Diverging)
- Use: diverging data with strong color variation.
- Example:
scale_fill_distiller(palette = "Spectral")
- ggsci — “jama” (Qualitative)
- Use: scientific journal style palettes.
- Example:
scale_color_jama()
- Tableau (via ggthemes or manually) — “Tableau 10” (Qualitative)
- Use: dashboard-style categorical palettes familiar to many readers.
- Example (manual):
tableau10 <- c("#4E79A7","#F28E2B","#E15759","#76B7B2","#59A14F","#EDC948","#B07AA1","#FF9DA7","#9C755F","#BAB0AC") scale_color_manual(values = tableau10)
- okabe-ito — “Okabe-Ito” (Qualitative, colorblind-friendly)
- Use: colorblind-safe categorical palette.
- Example:
okabe <- c("#E69F00","#56B4E9","#009E73","#F0E442","#0072B2","#D55E00","#CC79A7","#000000") scale_color_manual(values = okabe)
- polychrome — “createPalette” (Qualitative, many colors)
- Use: generate large sets of maximally distinct colors.
- Example:
library(polychrome) palette <- createPalette(12, seedcolors = c("#ff0000","#00ff00")) scale_color_manual(values = palette)
Applying palettes: examples
Base R: barplot with RColorBrewer
library(RColorBrewer) vals <- c(10, 20, 15, 5) barplot(vals, col = brewer.pal(4, "Set2"), border = NA)
ggplot2: continuous map with viridis
library(ggplot2) library(viridis) ggplot(mpg, aes(displ, hwy, color = cty)) + geom_point(size = 3) + scale_color_viridis_c(option = "plasma")
ggplot2: categorical with Okabe-Ito
ggplot(mtcars, aes(factor(cyl), fill = factor(am))) + geom_bar(position = "dodge") + scale_fill_manual(values = okabe)
Accessibility considerations
- For continuous scales prefer perceptually uniform palettes (viridis, colorspace HCL).
- Test palettes for common color vision deficiencies (deuteranopia, protanopia, tritanopia).
- Ensure sufficient contrast between plot elements and background (produce grayscale checks).
- Use shape, size, or labels in addition to color when possible.
Tips for choosing and customizing palettes
- Start with palette type: qualitative for categories, sequential for ordered single-hue, diverging for data with meaningful center.
- Use colorRampPalette or scales::gradient_n_pal to interpolate between colors.
- In ggplot2, use scale_color_manual/scale_fill_manual for discrete palettes and scale_color_gradientn/scale_fill_gradientn for custom continuous palettes.
- Save palettes as vectors for reuse:
my_palette <- c("#1b9e77","#d95f02","#7570b3")
Quick reference: when to use which
- Publication-ready, accessible continuous: viridis (magma, plasma, inferno)
- Maps and choropleths: YlGnBu, Blues
- Distinct categories (few): Set1, Dark2, Tableau 10
- Large numbers of distinct categories: polychrome, custom colorRampPalette
- Colorblind-safe categorical: Okabe-Ito, viridis (for ordered)
Example: full workflow — map with diverging palette and centered midpoint
library(ggplot2); library(RColorBrewer) df <- data.frame(region = state.abb, value = rnorm(50)) ggplot(df, aes(region, value, fill = value)) + geom_col() + scale_fill_distiller(palette = "RdYlBu", limits = c(-3,3), oob = scales::squish)
Resources and packages to explore
- RColorBrewer, viridis, colorspace, wesanderson, ggsci, ggthemes, polychrome, scales, grDevices.
This reference should give you practical options and code snippets for using 20 popular R palettes across common plotting scenarios. If you want, I can: generate downloadable palette vectors, create palette comparison plots, or produce colorblindness-simulated previews for any specific palette.
Leave a Reply