重要星的位置由place_points 函数在corrplot 函数中定义。
问题:
如果两者都显示,相关系数和显着性水平应该显示,它们重叠(我用黄色表示星星,因为我有一些色觉问题......)。
library(corrplot)
#> corrplot 0.90 loaded
M<-cor(mtcars)
res1 <- cor.mtest(mtcars, conf.level = .95)
corrplot(cor(mtcars),
method="square",
type="lower",
p.mat = res1$p,
insig = "label_sig",
sig.level = c(.001, .01, .05),
pch.cex = 0.8,
pch.col = "yellow",
tl.col="black",
tl.cex=1,
addCoef.col = "black",
tl.pos="n",
outline=TRUE)
由reprex package (v2.0.1) 于 2021 年 10 月 13 日创建
快速且临时(每次新加载 corrplot 包时都必须重新执行此步骤)解决方案:
在corrplot 函数中更改place_points 函数。为此,请运行:
trace(corrplot, edit=TRUE)
然后在第 443 行替换
place_points = function(sig.locs, point) {
text(pos.pNew[, 1][sig.locs], pos.pNew[, 2][sig.locs],
labels = point, col = pch.col, cex = pch.cex,
lwd = 2)
与:
# adjust text(X,Y ...) according to your needs, here +0.25 is added to the Y-position
place_points = function(sig.locs, point) {
text(pos.pNew[, 1][sig.locs], (pos.pNew[, 2][sig.locs])+0.25,
labels = point, col = pch.col, cex = pch.cex,
lwd = 2)
然后点击“保存”按钮。
结果:
library(corrplot)
#> corrplot 0.90 loaded
#change the corrplot function as described above
trace(corrplot, edit=TRUE)
#> Tracing function "corrplot" in package "corrplot"
#> [1] "corrplot"
M<-cor(mtcars)
res1 <- cor.mtest(mtcars, conf.level = .95)
corrplot(cor(mtcars),
method="square",
type="lower",
p.mat = res1$p,
insig = "label_sig",
sig.level = c(.001, .01, .05),
pch.cex = 0.8,
pch.col = "yellow",
tl.col="black",
tl.cex=1,
addCoef.col = "black",
tl.pos="n",
outline=TRUE)
由reprex package (v2.0.1) 于 2021 年 10 月 13 日创建