Jul 09, 2026 — Digital Edition
George Ideas
Independent Journalism & Insight
Feature

Mastering Discrete Color Palettes in ggplot2

ggplot2, a popular data visualization library in R, offers a wide range of color palettes that can significantly enhance the aesthetics and readability of your plots. When working with discrete data, choosing the right color palette is crucial to distinguish different categories and avoid color confusion. In this article, we will delve into the world of ggplot2 discrete color palettes, exploring their types, best practices, and how to create your own.

Color Combinaisons: Palette for Graphic Design #62
Color Combinaisons: Palette for Graphic Design #62

ggplot2 provides a variety of built-in color palettes that are designed to be both visually appealing and functionally useful. These palettes are not only pleasing to the eye but also follow colorblind-friendly guidelines to ensure accessibility for all viewers.

Palettes Pinterest couleurs 2026
Palettes Pinterest couleurs 2026

Built-in Discrete Color Palettes

ggplot2 offers several built-in discrete color palettes that can be easily applied to your plots. These palettes include:

Colour Palette Ideas, Warm Colours, Spring Wedding Ideas, Color Scheme, Late Summer Wedding Colors, Enchanted Forest Color Palette, Vintage Color Palette, Wedding Colour Schemes, Summer Colour Palette
Colour Palette Ideas, Warm Colours, Spring Wedding Ideas, Color Scheme, Late Summer Wedding Colors, Enchanted Forest Color Palette, Vintage Color Palette, Wedding Colour Schemes, Summer Colour Palette

  • viridis: A modern and colorblind-friendly palette that comes in several variations (e.g., 'viridis', 'inferno', 'plasma', 'magma').
  • tableau: A palette inspired by Tableau's default colors, offering a set of 20 distinct hues.
  • dark2 and light2: Two palettes designed for use with dark and light backgrounds, respectively, containing 8 colors each.
  • wesanderson: A vibrant palette inspired by the films of Wes Anderson, featuring 12 unique colors.

Applying Built-in Palettes

muted spring color palette
muted spring color palette

To apply a built-in palette to your ggplot2 plot, you can use the scale_color_manual or scale_fill_manual functions, depending on whether you're working with colors or fills. Here's an example using the 'viridis' palette:

library(ggplot2)
ggplot(mpg, aes(x = displ, y = hwy, color = class)) +
  geom_point() +
  scale_color_manual(values = viridis(5))

Customizing Built-in Palettes

'Grab Coffee With Me' Color Palette
'Grab Coffee With Me' Color Palette

While the built-in palettes offer a great starting point, you may want to customize them to better suit your needs. ggplot2 allows you to modify the number of colors in a palette or change the order of colors. Here's how you can create a custom 'viridis' palette with 7 colors:

custom_viridis <- viridis(7)
ggplot(mpg, aes(x = displ, y = hwy, color = class)) +
  geom_point() +
  scale_color_manual(values = custom_viridis)

Creating Your Own Discrete Color Palettes

Color Combinaisons: Palette for Graphic Design #130
Color Combinaisons: Palette for Graphic Design #130

If you can't find a suitable palette among the built-in options, you can create your own discrete color palette using various R packages and functions. One popular package for creating custom color palettes is RColorBrewer.

Using RColorBrewer

some white flowers with different colors on them
some white flowers with different colors on them
Lifetime Access Color Palette Studio: Procreate, Canva, Adobe (digital Download) - Etsy
Lifetime Access Color Palette Studio: Procreate, Canva, Adobe (digital Download) - Etsy
5 Colour Pallet Covers "Bluey Days" Aesthetic Themed 🩵
5 Colour Pallet Covers "Bluey Days" Aesthetic Themed 🩵
Color palettes for your next project
Find more color palettes in my book, Colors for Designers
Link in Bio

Steal these for later!

-
#Design #colorcombination #palette #Colors #graphicdesign Color Combos With Hex Code, 3 Colour Palette, Color Combination Palette, Cutecore Color Palette, Website Color Palette Branding, Educational Color Palette, Color Palette Branding, Color Palette Combinations, Warm Color Palette
Color palettes for your next project Find more color palettes in my book, Colors for Designers Link in Bio Steal these for later! - #Design #colorcombination #palette #Colors #graphicdesign Color Combos With Hex Code, 3 Colour Palette, Color Combination Palette, Cutecore Color Palette, Website Color Palette Branding, Educational Color Palette, Color Palette Branding, Color Palette Combinations, Warm Color Palette
a bunch of flowers that are sitting in the middle of some sort of color scheme
a bunch of flowers that are sitting in the middle of some sort of color scheme
5 Colour Pallet Covers "Hula Girl" Aesthetic Themed ❤️
5 Colour Pallet Covers "Hula Girl" Aesthetic Themed ❤️
an image of a street sign with different colors on it and the words below it
an image of a street sign with different colors on it and the words below it
Color Palette 150
Color Palette 150
the font and color scheme for this website
the font and color scheme for this website
Color Combinaisons: Palette for Graphic Design #139
Color Combinaisons: Palette for Graphic Design #139
5 Colour Pallet Covers "Figue" Aesthetic Themed 💜💛
5 Colour Pallet Covers "Figue" Aesthetic Themed 💜💛
5 Colour Pallet Covers "Nordland Blue" Aesthetic Themed ❤️
5 Colour Pallet Covers "Nordland Blue" Aesthetic Themed ❤️
a bunch of different types of font and numbers on top of each other in the same color
a bunch of different types of font and numbers on top of each other in the same color
some people are looking at each other in the same direction, and one person is not smiling
some people are looking at each other in the same direction, and one person is not smiling
a poster with different colors and styles of shoes on top of each other's feet
a poster with different colors and styles of shoes on top of each other's feet
Color Combinaisons: Palette for Graphic Design #148
Color Combinaisons: Palette for Graphic Design #148
【Color Palette】黄花の余白|Golden Petal Stillness
【Color Palette】黄花の余白|Golden Petal Stillness
【Color Palette】薄桃のさざ波|Blush-Tinged Waves
【Color Palette】薄桃のさざ波|Blush-Tinged Waves
four different font styles with different colors
four different font styles with different colors

RColorBrewer offers a wide range of color palettes that can be easily customized. Here's how to create a 5-color palette using the 'Dark2' scheme:

library(RColorBrewer)
dark2_palette <- brewer.pal(5, "Dark2")
ggplot(mpg, aes(x = displ, y = hwy, color = class)) +
  geom_point() +
  scale_color_manual(values = dark2_palette)

Creating a Custom Color Palette

If you have specific colors in mind, you can create a custom color palette using RGB or hex values. Here's an example of creating a 5-color palette with RGB values:

custom_palette <- c("#1f77b4", "#aec7e8", "#ff7f0e", "#2ca02c", "#d62728")
ggplot(mpg, aes(x = displ, y = hwy, color = class)) +
  geom_point() +
  scale_color_manual(values = custom_palette)

In conclusion, ggplot2 offers a wealth of discrete color palettes that can help you create visually appealing and informative plots. Whether you're using built-in palettes or creating your own, understanding the principles of color selection and customization will elevate your data visualizations to new heights. So go ahead, experiment with different palettes, and make your data shine!