[英]Dendrogram with Corrplot (R)
The closest solution I know of is to use a heatmap on a correlation matrix, for example you could also use gplots::heatmap.2.我所知道的最接近的解决方案是在相关矩阵上使用热图,例如您也可以使用 gplots::heatmap.2。
Here is how to do it using the heatmaply R package, which also offers an interactive interface where you can zoom-in and get a tooltip when hovering over the cells:以下是使用 heatmaply R 包的方法,该包还提供了一个交互式界面,您可以在其中放大并在将鼠标悬停在单元格上时获得工具提示:
# for the first time:
# install.packages("heatmaply")
library(heatmaply)
my_cor <- cor(mtcars)
heatmaply_cor(my_cor)
Here is how it looks:这是它的外观:
You can learn more about heatmaply in this vignette .您可以在此小插图中了解有关 heatmaply 的更多信息。
heatmaply actually has this functionality baked in since about December 2017!自 2017 年 12 月左右以来,heatmaply 实际上具有此功能! See the example below taken from the upcoming v1.0 vignette:请参阅以下来自即将发布的 v1.0 小插图的示例:
library("heatmaply")
r <- cor(mtcars)
## We use this function to calculate a matrix of p-values from correlation tests
## https://stackoverflow.com/a/13112337/4747043
cor.test.p <- function(x){
FUN <- function(x, y) cor.test(x, y)[["p.value"]]
z <- outer(
colnames(x),
colnames(x),
Vectorize(function(i,j) FUN(x[,i], x[,j]))
)
dimnames(z) <- list(colnames(x), colnames(x))
z
}
p <- cor.test.p(mtcars)
heatmaply_cor(
r,
node_type = "scatter",
point_size_mat = -log10(p),
point_size_name = "-log10(p-value)",
label_names = c("x", "y", "Correlation")
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.