Minimal example:
library(ggplot2)
x <- c(1:3)
y <- c(1:3)
data <- expand.grid(X=x, Y=y)
data$Z <- runif(9)
ggplot(data, aes(X, Y, fill=Z)) +
geom_tile()
Produces this:
How do you get the Z scale bar on the right to run from 0 on top to 1 on the bottom? instead of from bottom to top?
I'm trying to emphasize smaller values, and actually would like for this to work with viridis or magma color scheme if possible. But direction=-1
on scale_fill_viridis
only flips the color scale. Would like yellow = 0, blue/black = 1. Then Z scale to go from blue to yellow from bottom to top.
ggplot(data, aes(X, Y, fill=Z)) +
geom_tile() +
scale_fill_viridis(discrete=FALSE, direction=-1)
In the
scale_fill_distiller
you can select the palette and the direction of the palette.