带有 corrplot 的不均匀色标

Non-uniform colour scale with corrplot

是否可以在 corrplot 的色标中使用非均匀中断?下面的代码

library(RColorBrewer)
library(corrplot)
M <- matrix(runif(25,min=-1,max=1),nrow=5)
corrplot(M,is.corr=FALSE,cl.lim = c(-1, 1),col = brewer.pal(n = 6, name = "RdBu"))

产生a plot like this one.

您可以看到颜色在 -1 和 1 之间均匀分布。是否可以让这些中断发生在指定位置?例如说 0.2 和 0.8,而不是 0.33 和 0.66?

编辑:此外,是否可以指定每个分隔符旁边的文本,而不是数值?或者沿着颜色条移动该文本位置。我想我只是不确定如何访问 colourbar 本身的设置,除了 cl.lim 等提供的选项

提前致谢!

据我所知,没有任何方法可以更改错误图的这些方面,抱歉。一种可能的替代方法是使用 ggplot 绘制相关性并通过“比例”更改 breaks/labels,例如

library(tidyverse)
library(corrplot)
library(psych)

M <- matrix(runif(25, min = -1, max = 1), nrow = 5)
rownames(M) <- 1:5
colnames(M) <- 1:5
df <- corr.test(M)

df$r %>%
  as.data.frame() %>% 
  rownames_to_column("id") %>%
  pivot_longer(-c(id), names_to = "samples", values_to = "Correlation") %>% 
  ggplot() + 
  geom_raster(aes(x = samples, y = id, fill = Correlation)) +
  scale_fill_distiller(palette = "RdBu",
                       breaks = c(-0.8, -0.2, 0.2, 0.8),
                       labels = c("strong -ve corr",
                                  "weak -ve corr",
                                  "weak +ve corr",
                                  "strong +ve corr"))

或者,如果您想将超出特定范围的值的方块涂成灰色:

df$r %>%
  as.data.frame() %>% 
  rownames_to_column("id") %>%
  pivot_longer(-c(id), names_to = "samples", values_to = "Correlation") %>% 
  ggplot() + 
  geom_raster(aes(x = samples, y = id, fill = Correlation)) +
  scale_fill_distiller(palette = "RdBu",
                       breaks = c(-0.8, -0.2, 0.2, 0.8),
                       labels = c("strong -ve corr",
                                  "weak -ve corr",
                                  "weak +ve corr",
                                  "strong +ve corr"),
                       limits = c(-1, 0.99))