Here's an approach using scales::pseudo_log_trans, which lets us plot 0 but transition to a log scaling beyond 1.
my_breaks <- c(0, 0.01, 0.1, 1, 10, 100)
ggplot(data = my_data, aes(x = sample_name,
y = sample_genus,
fill = sample_abundance)) +
geom_tile() +
scale_fill_viridis_c(breaks = my_breaks, labels = my_breaks,
trans = scales::pseudo_log_trans(sigma = 0.001))

Tidyverse
ggplot2.tidyverse.org › reference › scale_viridis.html
Viridis colour scales from viridisLite — scale_colour_viridis_d • ggplot2
See also https://bids.github.io/colormap/. scale_colour_viridis_d( name = waiver(), ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", aesthetics = "colour" ) scale_fill_viridis_d( name = waiver(), ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", aesthetics = "fill" ) scale_colour_viridis_c( name = waiver(), ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", values = NULL, space = "Lab", na.value = "grey50", guide = "colourbar", aesthetics = "colour" ) scale_fill_viridis_c( name = waiver(), ..., alpha = 1, begin = 0, end = 1, direction = 1, option =
Sjmgarnier
sjmgarnier.github.io › viridis › reference › scale_viridis.html
Viridis Color Scales for ggplot2 — scale_fill_viridis • viridis
See viridis and viridis.map for more information on the color palettes. scale_fill_viridis( ..., alpha = 1, begin = 0, end = 1, direction = 1, discrete = FALSE, option = "D", aesthetics = "fill" ) scale_color_viridis( ..., alpha = 1, begin = ...
Jose M Sallan blog
jmsallan.netlify.app › blog › the-viridis-palettes
The viridis palettes - Jose M Sallan blog
In this figure, I represent the value of the two-variable function with a color scale. I have used the magma palette of viridis with scale_fill_viridis_c: ggplot(grid, aes(x = x, y = y, fill = z)) + geom_tile() + theme_void() + scale_fill_viridis_c(name = "sin(x) + cos(y)", option = "magma") + theme(legend.position = "bottom") + labs(title = "Colors with magma palette")
Tmieno2
tmieno2.github.io › R-as-GIS-for-Economists › color-scale.html
8.3 Color scale | R as GIS for Economists
For example, scale_fill_viridis_c() can be used for fill aesthetics applied to a continuous variable. There are five types of palettes available under the viridis color map and can be selected using the option = option.
CRAN
cran.r-project.org › web › packages › viridis › vignettes › intro-to-viridis.html
Introduction to the viridis color maps
For ggplot, use scale_color_viridis() and scale_fill_viridis():
O'Reilly Media
ggplot2-book.org › scales-colour.html
11 Colour scales and legends – ggplot2: Elegant Graphics for Data Analysis (3e)
erupt erupt + scale_fill_viridis_c() erupt + scale_fill_viridis_c(option = "magma") For most use cases, the viridis scales will work better than other continuous scales built into ggplot2, but there are other options that are useful in some situations. A second group of continuous colour scales built in to ggplot2 are derived from the ColorBrewer scales: scale_fill_brewer() provides these colours as discrete palettes, while scale_fill_distiller() and scale_fill_fermenter() are the continuous and binned analogs.
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.
Rdrr.io
rdrr.io › cran › ggplot2 › man › scale_viridis.html
scale_viridis: Viridis colour scales from viridisLite in ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics
April 22, 2026 - See also https://bids.github.io/colormap/. scale_colour_viridis_d( name = waiver(), ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", aesthetics = "colour" ) scale_fill_viridis_d( name = waiver(), ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", aesthetics = "fill" ) scale_colour_viridis_c( name = waiver(), ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", values = NULL, space = "Lab", na.value = "grey50", guide = "colourbar", aesthetics = "colour" ) scale_fill_viridis_c( name = waiver(), ..., alpha = 1, begin = 0, end = 1, direction = 1, option =
Top answer 1 of 4
24
EDIT 2022-05-03: The scale function is called scale_fill_viridis_c() these days.
@ClausWilke's solution is better because it shows in the legend, but sometimes one just needs a quick solution without having to write too much specific code. This one also relies on the scales package
ggplot(DataSet2, aes(x, y, fill = z)) +
geom_tile() +
scale_fill_viridis_c(limits = c(0.2, 1), oob = scales::squish) +
geom_text(aes(label = round(z, 2)), size = 2)

2 of 4
16
You can define an arbitrary rescaling function. Not sure this looks that great, would likely need some work with the legend, but in principle this mechanism allows you to map data values onto the scale in any way you want.
ggplot(DataSet2, aes(x, y, fill = z)) +
geom_tile() +
scale_fill_viridis(rescaler = function(x, to = c(0, 1), from = NULL) {
ifelse(x<1.2,
scales::rescale(x,
to = to,
from = c(min(x, na.rm = TRUE), 1.2)),
1)}) +
geom_text(aes(label = round(z, 2)), size = 2)

R Project
search.r-project.org › CRAN › refmans › ggplot2 › html › scale_viridis.html
R: Viridis colour scales from viridisLite
See also https://bids.github.io/colormap/. scale_colour_viridis_d( name = waiver(), ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", aesthetics = "colour" ) scale_fill_viridis_d( name = waiver(), ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", aesthetics = "fill" ) scale_colour_viridis_c( name = waiver(), ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", values = NULL, space = "Lab", na.value = "grey50", guide = "colourbar", aesthetics = "colour" ) scale_fill_viridis_c( name = waiver(), ..., alpha = 1, begin = 0, end = 1, direction = 1, option =
Wilkelab
wilkelab.org › SDS366 › worksheets › color-scales.html
Color scales – SDS 366
ggplot(temps_months, aes(x = month, y = location, fill = mean)) + geom_tile() + coord_fixed(expand = FALSE) + scale_fill_viridis_c() The viridis scales can be customized with direction (as before), option (which can be "A", "B", "C", "D", or "E"), and begin and end which are numerical values ...
RDocumentation
rdocumentation.org › packages › viridis › versions › 0.5.1 › topics › scale_color_viridis
scale_color_viridis function - RDocumentation
scale_fill_viridis(..., alpha = 1, begin = 0, end = 1, direction = 1, discrete = FALSE, option = "D") ... The (corrected) hue in [0,1] at which the viridis colormap begins. ... The (corrected) hue in [0,1] at which the viridis colormap ends. ... Sets the order of colors in the scale.
RDocumentation
rdocumentation.org › packages › viridis › versions › 0.6.2 › topics › scale_fill_viridis
scale_fill_viridis function - RDocumentation
Sets the order of colors in the scale. If 1, the default, colors are as output by viridis_pal. If -1, the order of colors is reversed. ... Generate a discrete palette? (default: FALSE - generate continuous palette). ... A character string indicating the color map option to use.
Tidyverse
ggplot2.tidyverse.org › reference › scale_colour_continuous.html
Continuous and binned colour scales — scale_colour_continuous • ggplot2
The preferred method to change ... If you want to manually set the colors of a scale, consider using scale_colour_gradient() or scale_colour_steps()....
Lets-Plot
lets-plot.org › python › pages › api › lets_plot.scale_fill_viridis.html
scale_fill_viridis() | Lets-Plot Python API
Search Ctrl+K · GitHub · scale_fill_viridis(alpha=None, begin=None, end=None, direction=None, option=None, name=None, breaks=None, labels=None, lablim=None, limits=None, na_value=None, guide=None, trans=None, format=None)# The viridis color maps are designed to be perceptually-uniform, both in regular form and also when converted to black-and-white.
Dongzhuoer
bookdown.dongzhuoer.com › hadley › ggplot2-book › colour-continuous
10.2 Continuous colour scales | ggplot2
erupt erupt + scale_fill_viridis_c() erupt + scale_fill_viridis_c(option = "magma") The second group of continuous colour scales built in to ggplot2 are derived from the ColorBrewer scales: scale_fill_brewer() provides these colours as discrete palettes, while scale_fill_distiller() and scale_fill_fermenter() are the continuous and binned analogs.
Uib
bioceed.uib.no › dropfolder › bioSTATS › Rmd › Visualizing › Essential › choosing-colors.html
choosing-colors.utf8
The palettes were also designed ... scale_fill_viridis_d() (when handling discrete predictor variables) and scale_fill_viridis_c() (when handling continuous predictor variables)....
RDocumentation
rdocumentation.org › packages › viridis › versions › 0.6.5 › topics › scale_fill_viridis
scale_fill_viridis Viridis Color Scales for ggplot2
If 1, the default, colors are as output by viridis_pal. If -1, the order of colors is reversed. ... Generate a discrete palette? (default: FALSE - generate continuous palette). ... A character string indicating the color map option to use. Eight options are available: ... Character string or vector of character strings listing the name(s) of the aesthetic(s) that this scale works with. This can be useful, for example, to apply colour settings to the colour and fill aesthetics at the same time, via aesthetics = c("colour", "fill").
GitHub
github.com › tidyverse › ggplot2 › blob › main › man › scale_viridis.Rd
ggplot2/man/scale_viridis.Rd at main · tidyverse/ggplot2
\alias{scale_fill_ordinal} \alias{scale_color_viridis_d} \alias{scale_color_viridis_c} \alias{scale_color_viridis_b} \title{Viridis colour scales from viridisLite} \usage{ scale_colour_viridis_d( name = waiver(), ..., alpha = 1, begin = 0, end = 1, direction = 1, option = "D", aesthetics = "colour" ) ·
Author: tidyverse