ggcorr函数执行平方相关矩阵的问题
Problems with the ggcorr function to perform square correlation matrix
我正在尝试使用 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,n+0.5,by=1)) +
geom_text(aes(x=y,y=x,label=round(coefficient,2)),col="steelblue")
我正在尝试使用 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,n+0.5,by=1)) +
geom_text(aes(x=y,y=x,label=round(coefficient,2)),col="steelblue")