我有一个排名相关矩阵。 我想用半色三角形相关矩阵可视化彩色树状图热图.2“gplots”的功能,我失败了,因为我不知道该怎么做。 然后我尝试了R包“corrgram”和“corrplot”,在那里我可以看到半三角相关矩阵,但不能绘制树状图,表明基于spearman相关性的样本聚类
我最好的尝试是使用corrgram包
panel.shadeNtext <- function (x, y, corr = NULL, col.regions, ...)
{
corr <- cor(x, y, use = "pair")
results <- cor.test(x, y, alternative = "two.sided")
est <- results$p.value
stars <- ifelse(est < 5e-4, "***",
ifelse(est < 5e-3, "**",
ifelse(est < 5e-2, "*", "")))
ncol <- 14
pal <- col.regions(ncol)
col.ind <- as.numeric(cut(corr, breaks = seq(from = -0.8, to = 1.2,
length = ncol + 1), include.lowest = TRUE))
usr <- par("usr")
rect(usr[1], usr[3], usr[2], usr[4], col = pal[col.ind],
border = NA)
box(col = "white")
on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- formatC(corr, digits = 2, format = "f")
cex.cor <- .8/strwidth("-X.xx")
fonts <- ifelse(stars != "", 1,1)
# option 1: stars:
text(0.5, 0.4, paste0(stars), cex = cex.cor)
# option 2: bolding:
#text(0.5, 0.5, r, cex = cex.cor, font=fonts)
}
col.corrgram <- function(ncol){
colorRampPalette(c("blue", "lightblue", "red", "darkred"))(ncol)}
corrgram(data.full[,c(2:ncol(data.full))], type="data",lower.panel=panel.shadeNtext,
upper.panel=NULL, text.panel=panel.txt, col=col.corrgram)
dev.off()
请帮我把彩色树状图放在这个相关图上
提前致谢