小编Est*_*her的帖子

从 hclust(分层聚类)对象中提取距离

我想计算我的聚类分析解决方案对实际距离分数的拟合程度。为此,我需要提取我正在聚类的刺激之间的距离。我知道在查看 树状图时我可以提取距离,例如 5 到 -14 之间的距离是 0.219(它们连接处的高度),但是是否有一种自动方法可以从 hclust 中的信息中提取距离目的?

List of 7
 $ merge      : int [1:14, 1:2] -5 -1 -6 -4 -10 -2 1 -9 -12 -3 ...
 $ height     : num [1:14] 0.219 0.228 0.245 0.266 0.31 ...
 $ order      : int [1:15] 3 11 5 14 4 1 8 12 10 15 ...
 $ labels     : chr [1:15] "1" "2" "3" "4" ...
 $ method     : chr "ward.D"
 $ call       : language hclust(d = as.dist(full_naive_eucAll, diag …
Run Code Online (Sandbox Code Playgroud)

r dendrogram hclust dendextend

5
推荐指数
1
解决办法
2059
查看次数

使用牛皮图将x轴切换到顶部时左对齐轴标签

我正在尝试制作一个相关热图,其中x轴使用移动到顶部cowplot::switch_axis_position.我有不同长度的轴标签,我希望标签左对齐(或者更确切地说是底部对齐,因为它们旋转了90度).虽然我设法对齐标签,但它们会远远超出情节.

library(reshape2)
library(ggplot2)
library(cowplot)

# some toy data
set.seed(1)
mydata <- mtcars[, c(1, 3, 4, 5, 6, 7)]

# to show difference in justification better, make names of unequal length 
names(mydata) = paste0(sample(c("mtcars_", ""), 6, replace = TRUE), names(mydata))
cormat <- round(cor(mydata), 2)

melted_cormat <- melt(cormat)
head(melted_cormat)
Run Code Online (Sandbox Code Playgroud)

首先是x轴移动到顶部,标签垂直居中的图:

plot <- ggplot(data = melted_cormat, aes(x=Var1, y=Var2, fill=value)) + 
        geom_tile() +
        theme_bw(base_size=20) + xlab("") + ylab("") +
        theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 0.5))
ggdraw(switch_axis_position(plot, 'x')) …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 cowplot

5
推荐指数
1
解决办法
706
查看次数

标签 统计

r ×2

cowplot ×1

dendextend ×1

dendrogram ×1

ggplot2 ×1

hclust ×1