Generate correlation matrix with specific columns and only with significant values in corrplot
I would use the well established Hmisc::rcorr
for the calculations. In corrplot::corrplot
, subset both the corr=
and the p.mat=
with [1:6, 7:14]
.
c_df <- Hmisc::rcorr(cor(correlation_df), type='spearman')
library(corrplot)
corrplot(corr=c_df$r[1:6, 7:14], p.mat=c_df$P[1:6, 7:14], sig.level=0.05,
method='color', diag=FALSE, addCoef.col=1, type='upper', insig='blank',
number.cex=.8)
This appears to correspond to the p-values.
m <- c_df$P[1:6, 7:14] < .05
m[lower.tri(m, diag=TRUE)] <- ''
as.data.frame(replace(m, lower.tri(m, diag=TRUE), ''))
# Al Fe Mn Zn Mo Baresoil Humdepth pH
# N FALSE FALSE TRUE FALSE FALSE FALSE FALSE
# P TRUE TRUE FALSE FALSE FALSE FALSE
# K TRUE FALSE FALSE FALSE TRUE
# Ca FALSE TRUE TRUE FALSE
# Mg TRUE TRUE TRUE
# S FALSE FALSE