最小的例子:
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()
产生这个:
如何让右侧的 Z 比例尺从顶部的 0 运行到底部的 1?而不是从下到上?
我试图强调较小的值,如果可能的话,实际上希望它能够与 viridis 或 magma 配色方案一起使用。但direction=-1
onscale_fill_viridis
只会翻转色阶。想要黄色 = 0,蓝色/黑色 = 1。然后 Z 刻度从底部到顶部从蓝色变为黄色。
ggplot(data, aes(X, Y, fill=Z)) +
geom_tile() +
scale_fill_viridis(discrete=FALSE, direction=-1)