This is basically the same as @seasmith's answer, except with the addition of saving the palette to a variable to use later. I do this often for explicitly setting a NA color and then using the palette across multiple plots.

Other packages have similar functions to the viridis ones: for example, you can get ColorBrewer palettes from RColorBrewer::brewer.pal, CartoColor palettes from rcartocolor::carto_pal, or any of the ggthemes ones from functions with the same name as the palette.

library(tidyverse)

plasma_pal <- c("red", viridis::plasma(n = 6))

plasma_pal
#> [1] "red"       "#0D0887FF" "#6A00A8FF" "#B12A90FF" "#E16462FF" "#FCA636FF"
#> [7] "#F0F921FF"

iris %>%
    ggplot(aes(Sepal.Length, Sepal.Width, color = cut(Petal.Length, 0:7))) + 
    geom_point() +
    scale_color_manual(values = plasma_pal)

Created on 2018-04-19 by the reprex package (v0.2.0).

Answer from camille on Stack Overflow
🌐
Tidyverse
ggplot2.tidyverse.org › reference › scale_viridis.html
Viridis colour scales from viridisLite — scale_colour_viridis_d • ggplot2
# viridis is the default colour/fill scale for ordered factors set.seed(596) dsamp <- diamonds[sample(nrow(diamonds), 1000), ] ggplot(dsamp, aes(carat, price)) + geom_point(aes(colour = clarity)) # Use viridis_d with discrete data txsamp <- subset(txhousing, city %in% c("Houston", "Fort Worth", "San Antonio", "Dallas", "Austin")) (d <- ggplot(data = txsamp, aes(x = sales, y = median)) + geom_point(aes(colour = city))) d + scale_colour_viridis_d() # Change scale label d + scale_colour_viridis_d("City\nCenter") # Select palette to use, see ?scales::pal_viridis for more details d + scale_colour_v
🌐
Waldyrious
waldyrious.net › viridis-palette-generator
Viridis Color Palette Generator
Popular for good reason, the palettes are colorblind-friendly, retain representational clarity in greyscale, and are generally aesthetically pleasing. This tool provides a convenience wrapper around D3js's viridis implementation for use in data visualization tools with manual color value specification (e.g., Microsoft Excel, ArcGIS, and Tableau to name a few).
Discussions

r - Modify viridis palette in ggplot - Stack Overflow
What I would like to do is to special-case the (0,1] value and color that in red but to retain the viridis gradient for the remaining values. I know I could change the color on the fly but I wonder if it's also possible to construct a new discrete color palette that has red as its first color ... More on stackoverflow.com
🌐 stackoverflow.com
`viridis` type for discrete scales ?
I noticed that scale_colour/fill_continuous has a type option specifying wheter to use gradient or viridis palettes. in order to enable color blindness friendly visualisation. Is there any particular reason why the same option is not (yet) implemented in scale_colour/fill_discrete or ... More on github.com
🌐 github.com
2
July 8, 2019
r - discretizing viridis ggplot color scale - Stack Overflow
I have an ordered factor variable that I would like to plot using ggplot2. Is there any way I can use scale_color_viridis(), a continuous color scale, with this ordered factor without casting the f... More on stackoverflow.com
🌐 stackoverflow.com
Something about the popular viridis palette
I write a small Substack about adaptive software, and my latest piece is about data visualization · By adaptive software I mean software that keeps adapting to users and changing after it ships More on reddit.com
🌐 r/datavisualization
🌐
Sjmgarnier
sjmgarnier.github.io › viridis › reference › scale_viridis.html
Viridis Color Scales for ggplot2 — scale_fill_viridis • viridis
Scale functions (fill and colour/color) for ggplot2. For discrete == FALSE (the default) all other arguments are as to scale_fill_gradientn or scale_color_gradientn. Otherwise the function will return a discrete_scale with the plot-computed number of colors. See viridis and viridis.map for more information on the color palettes.
🌐
CRAN
cran.r-project.org › web › packages › viridis › vignettes › intro-to-viridis.html
Introduction to the viridis color maps
It is immediately clear that the “rainbow” palette is not perceptually uniform; there are several “kinks” where the apparent color changes quickly over a short range of values. This is also true, though less so, for the “heat” colors. The other scales are more perceptually uniform, but “viridis” stands out for its large perceptual range.
🌐
RPubs
rpubs.com › mjvoss › psc_viridis
RPubs - Viridis Color Palette
August 10, 2021 - Viridis Color Palette · by Matthew Voss · Last updated about 5 years ago · Hide Comments (–) Share Hide Toolbars ·
🌐
R Graph Gallery
r-graph-gallery.com › package › viridis.html
Create beautiful color maps with Viridis
The filled.contour() function is a base R function that creates a filled contour plot. You can use the color.palette argument to specify a color palette from the viridis package.
🌐
Andrewheiss
datavizf24.classes.andrewheiss.com › resource › colors.html
Color palettes – Data Visualization with R
The viridis palettes come with {ggplot2} and you can use them with scale_fill_viridis_d()/scale_color_viridis_d() for discrete data and scale_fill_viridis_c()/scale_color_viridis_c() for continuous data.
Find elsewhere
🌐
DevGenius
blog.devgenius.io › the-art-of-color-schemes-in-r-base-and-viridis-palettes-141f2b613541
The Art of Color Schemes in R: base and viridis palettes | by Dima from Mithridata | Dev Genius
June 6, 2023 - The discrete = TRUE argument is used because the 'Species' variable is categorical. You probably wonder how it looks like when it is off. If you do, than we have to switch color ...
🌐
GitHub
github.com › tidyverse › ggplot2 › issues › 3428
`viridis` type for discrete scales ? · Issue #3428 · tidyverse/ggplot2
July 8, 2019 - I noticed that scale_colour/fill_continuous has a type option specifying wheter to use gradient or viridis palettes. in order to enable color blindness friendly visualisation. Is there any particular reason why the same option is not (yet) implemented in scale_colour/fill_discrete or scale_colour/fill_hue, respectively?
Author: tidyverse
🌐
RDocumentation
rdocumentation.org › packages › viridis › versions › 0.5.1 › topics › scale_color_viridis
scale_color_viridis function - RDocumentation
A character string indicating the colormap option to use. Four options are available: "magma" (or "A"), "inferno" (or "B"), "plasma" (or "C"), "viridis" (or "D", the default option) and "cividis" (or "E"). For discrete == FALSE (the default) all other arguments are as to scale_fill_gradientn or scale_color_gradientn.
🌐
Lospec
lospec.com › palette-list › tag › viridis
Palette List
We include both palettes that originate from old hardware that could only display a few colors, as well as palettes created by pixel artists specifically for making art. Usage Guide | Random Palette | Rejected Palettes | Your Likes | NEW October Palette Contest | September ... Palette based on Viridis color maps extended with brewer yellows.
🌐
Bookdown
bookdown.org › hneth › ds4psy › D-4-apx-colors-pkgs.html
D.4 Using color packages | Data Science for Psychologists
Actually, unless you happen to need very special colors, RColorBrewer provides nice and useful color palettes that are sufficient for most purposes. ... The color scales of the viridis package (Garnier, 2018a) were specifically designed to be perceptually-uniform, both in regular form and when converted to black-and-white.
🌐
Unibe
repec.sowi.unibe.ch › stata › palettes › colors.html
palettes - Color palettes, symbol palettes, and line pattern palettes for Stata graphs
Palettes from Tol (2012) ColorBrewer · Color schemes from Carto · Viridis colormaps · Seaborn colormaps · Other matplotlib maps · Colormaps by Kovesi (2015) Scientific colour maps · Semantic colors · Colors from spmap · Swiss Federal Statistical Office ·
🌐
ETH Zurich
stat.ethz.ch › R-manual › R-devel › library › grDevices › html › palettes.html
R: Color Palettes
The default HCL palette is the widely used viridis palette which is a sequential palette with relatively high chroma throughout so that it also works reasonably well as a qualitative palette. However, while viridis is a rather robust default palette, more suitable HCL palettes are available for most visualizations.
🌐
Jose M Sallan blog
jmsallan.netlify.app › blog › the-viridis-palettes
The viridis palettes - Jose M Sallan blog
The eight color schemes are beautiful, perceptually-uniform and accessible for people with color-blindness. We can generate viridis palettes of any number of colors, so we can use them to plot continuous, binned and discrete data.
🌐
Gotellilab
gotellilab.github.io › GotelliLabMeetingHacks › NickGotelli › ViridisColorPalette.html
Viridis color palette
September 6, 2018 - p4 + scale_fill_viridis_c(option="cividis") # "E" option · When working with discrete color scales, use the scale_fill_viridis_d() function.
🌐
Marshall
denvirlab.marshall.edu › BMR617-2023 › 09-Color.html
Color schemes in R
Search in Help for scale_color_viridis. The variants _b, _c, and _d are for “binned”, “continuous”, and “discrete”, so in our example we want scale_fill_viridis_d.