如何在corrplot中获得理想的色标?

问题描述 投票:0回答:2

我有一个矩阵,我试图使用 R 中的 corrplot 包进行可视化。该矩阵中的值是治疗组相对于对照组的倍数变化(1 表示没有变化,>1 表示治疗组增强, <1 meaning treatment group reduced). Is there a way to utilize corrplot such that all values < 1 are on a red gradient, all values > 1 在绿色渐变上,所有值 = 1 都是白色?

这是我尝试过的:

样本数据:

testdata = matrix(rnorm(10, 1, 0.1), nrow = 5)
testdata
          [,1]      [,2]
[1,] 1.1368602 1.0123854
[2,] 0.9774229 1.0215942
[3,] 1.1516471 1.0379639
[4,] 0.8451247 0.9497677
[5,] 1.0584614 0.9666793

corrplot(testdata, is.corr = FALSE, col.lim = c(0, max(testdata)))

产生以下内容:

Produced Plot

如您所见,值 > 1 与 < 1. If anyone is able to share any way to set a transition point on the corrplot package that places all values > 阈值之间没有分界,因为在一种颜色渐变上和所有值 < threshhold as being on another color gradient I would be extremely grateful! Thank you for your time.

r correlation r-corrplot ggcorrplot
2个回答
1
投票

你可以用

col
参数来做到这一点。

library(corrplot)
#> corrplot 0.92 loaded

set.seed(123)
testdata = matrix(rnorm(10, 1, 0.1), nrow = 5)
corrplot(testdata, 
         is.corr = FALSE, 
         col.lim = c(min(testdata), max(testdata)),
         col = COL2("RdBu"),
         )

创建于 2023-05-03 与 reprex v2.0.2


0
投票

我不知道你是否可以使用不均匀的发散尺度。但是对于一个均匀的分歧,最小值为 0,就像你说的那样,并且比例以 1 为中心,你可以这样做:

corrplot(testdata, is.corr = FALSE, col = COL2('RdBu', 10), col.lim = c(0, 2))

© www.soinside.com 2019 - 2024. All rights reserved.