如何解决ggcorr函数执行平方相关矩阵的问题
我正在尝试使用Pearson方法制作一个方阵,其中上三角部分包含相关的数值,下三角部分包含相应的颜色。
library(ggcorrplot)
library(corrplot)
dadosp=head(iris)[1:4]
matcor <- round(cor(dadosp),2)# matcor
ggcorr(matcor,palette = "Greys",name = expression(rho),method=c("pairwise","pearson"),max_size = 10,legend.position = " ",min_size = 2,position="triangsuperior",size = 3,hjust = 0.75,nbreaks = 6,angle = -45)
但是,出现以下错误:
Erro: Can't find `position` called 'triangsuperior'
Run `rlang::last_error()` to see where the error occurred.
我打算复制的示例在结构上类似于以下内容:
解决方法
尝试
corrplot.mixed(matcor)
您在寻找这个吗?
,您显示的情节来自corrplot。以下是对ggcorrplot的一种破解(OP的问题似乎将GGally的ggcorr和ggcorrplot混淆了):
library(dplyr)
library(ggcorrplot)
dadosp=head(iris)[1:4]
matcor <- round(cor(dadosp),2)# matcor
#set the diagonal to be zero first
diag(matcor) = 0
g = ggcorrplot(matcor,method="circle",type="upper",show.diag=TRUE)
# now we add the text and plot on top of the diagonal to give the lables
g + geom_text(aes(x=Var2,y=Var1,label=value)) +
geom_label(data=. %>% filter(Var1==Var2),aes(label=Var1)) +
theme(axis.text.x=element_blank(),axis.text.y=element_blank())
或使用GGally的ggcorr:
library(GGally)
n = ncol(dadosp)+1
g = ggcorr(dadosp,geom="circle")
g + geom_vline(xintercept=seq(1.5,n+0.5,by=1)) +
geom_hline(yintercept=seq(1.5,by=1)) +
geom_text(aes(x=y,y=x,label=round(coefficient,2)),col="steelblue")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。