Scale ggplot2 Color Gradient to Range Outside of Data (Example) | Specify Colors, Limits & Breaks

preview_player
Показать описание
R code of this video:

y = rep(seq(- 2, 2, 1), each = 5),
z = round(rnorm(25, 50, 70)))

library("ggplot2") # Load ggplot2

ggp <- ggplot(data, # Create raster with default colors
aes(x, y, fill = z)) +
geom_tile()
ggp # Draw raster

ggp + # Manually set color ranges
scale_fill_gradientn(colors = c("#1b98e0", "#f6f805", "#353436"))

ggp + # Manually set color ranges
scale_fill_gradientn(colors = c("#1b98e0", "#f6f805", "#353436"),
limits = c(- 200, 200),
breaks = c(- 200, - 100, 0, 100, 200))

Follow me on Social Media:

Рекомендации по теме
Комментарии
Автор

Danke sehr! Very helpful. Ggplot is confusing sometimes.

forrestoakley