1

最小的例子:

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=-1onscale_fill_viridis只会翻转色阶。想要黄色 = 0,蓝色/黑色 = 1。然后 Z 刻度从底部到顶部从蓝色变为黄色。

ggplot(data, aes(X, Y, fill=Z)) +
  geom_tile() +
  scale_fill_viridis(discrete=FALSE, direction=-1)

绿化

4

2 回答 2

0

我得到了它的工作trans = 'reverse'

ggplot(data, aes(X, Y, fill=Z)) +
  geom_tile() + 
  scale_fill_viridis(trans = 'reverse', option="plasma")

在此处输入图像描述

于 2021-04-28T16:59:22.777 回答
0

In the scale_fill_distiller you can select the palette and the direction of the palette.

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 = X, y = Y, fill = Z) +
  geom_tile(size = 1L) +
  scale_fill_distiller(palette = "Blues", direction = 1) +
  theme_minimal()

于 2021-04-28T16:36:50.197 回答