The `viridis`

package in R
significantly enhances data visualization by offering a collection of
**color maps that are perceptually uniform** in color and
brightness. Crafted with the needs of colorblind users in mind, this
package features color scales that **maintain clarity and
consistency** even when viewed in grayscale.

{Viridis}

The `viridis`

package in R is an extension of the ggplot2 package, designed to simplify
the process of creating visually appealing color maps. It offers a set
of color maps that are **perceptually uniform** in color
and brightness, making them ideal for use in data visualization.

To get started with `viridis`

, you can install it directly
from CRAN using the `install.packages`

function:

The `viridis`

package is very easy to use. Start by
loading it with `library(viridis)`

, and then you can use the
**color palettes** in your plots!

The `viridis`

package is an extension of the ggplot2 package, which means you can
use it to customize the color of your plots.

It provides `scale_color_viridis()`

and
`scale_fill_viridis()`

functions that allow you to use the
`viridis`

color palettes in your plots.

Example:

```
# load libraries
library(viridis)
library(ggplot2)
# create dataframe
dsub <- subset(diamonds, x > 5 & x < 6 & y > 5 & y < 6)
dsub$diff <- with(dsub, sqrt(abs(x - y)) * sign(x - y))
# create plot with Turbo color palette
ggplot(dsub, aes(x, y, colour = diff)) +
geom_point() +
scale_color_viridis(option='turbo') +
theme_minimal()
```

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.

Example:

```
library(viridis)
x <- y <- seq(-8*pi, 8*pi, len = 40)
r <- sqrt(outer(x^2, y^2, "+"))
filled.contour(
cos(r^2)*exp(-r/(2*pi)),
axes=FALSE,
color.palette=magma,
asp=1
)
```

The gallery is **filled** with examples that showcase
the versatility of the `viridis`

package. Each example is
designed to help you understand how to use **custom
colors** in your plots.

👋 After crafting hundreds of R charts over 12 years, I've distilled
my top 10 tips and tricks. Receive them via email!
**One insight per day for the next 10 days**! 🔥