Learn R Programming

viridis (version 0.2.5)

scale_color_viridis: Viridis color scales

Description

Uses the viridis color scale.

Usage

scale_color_viridis(..., alpha = 1, discrete = FALSE)

scale_fill_viridis(..., alpha = 1, discrete = FALSE)

Arguments

...
parameters to discrete_scale or scale_fill_gradientn
alpha
pass through parameter to viridis
discrete
generate a discrete palette? (default: FALSE - generate continuous palette)

Details

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 for more information on the color scale.

Examples

Run this code
library(ggplot2)

# ripped from the pages of ggplot2
p <- ggplot(mtcars, aes(wt, mpg))
p + geom_point(size=4, aes(colour = factor(cyl))) +
    scale_color_viridis(discrete=TRUE) +
    theme_bw()

# ripped from the pages of ggplot2
dsub <- subset(diamonds, x > 5 & x < 6 & y > 5 & y < 6)
dsub$diff <- with(dsub, sqrt(abs(x-y))* sign(x-y))
d <- ggplot(dsub, aes(x, y, colour=diff)) + geom_point()
d + scale_color_viridis() + theme_bw()


# from the main viridis example
dat <- data.frame(x = rnorm(10000), y = rnorm(10000))

ggplot(dat, aes(x = x, y = y)) +
  geom_hex() + coord_fixed() +
  scale_fill_viridis() + theme_bw()

library(MASS)
data(geyser, "MASS")

ggplot(geyser, aes(x = duration, y = waiting)) +
  xlim(0.5, 6) + ylim(40, 110) +
  stat_density2d(aes(fill = ..level..), geom="polygon") +
  scale_fill_viridis() +
  theme_bw()

Run the code above in your browser using DataLab