Complexheatmap中的Bray-Curtis距离计算方法?
Bray–Curtis distance calculation method in Complexheatmap?
我在 R 中使用 Complexheatmap 函数(或“热图”),想知道是否有一种方法可以使用 Bray-Curtis 方法计算 col/row 距离(使用 ward.D2 聚类方法) 因为它不是 Complexheatmap 中支持的方法。不幸的是,我需要使用这个函数而不是 heatmap.2 和 pheatmap。
这是一些虚构的鱼类计数数据(我的实际数据有 47 个站点(行)和 32 个季节,但我不确定如何在此处重新创建):
data<-matrix(rpois(30,0.9),ncol=6, nrow=5)
colnames(data) <- c("2004W", "2004D", "2005W", "2005D", "2006W", "2006D")
# I tried assigning the method this way:
d1 <- vegdist(log(data+1), method = "bray")
d2 <- vegdist(t(log(data+1)), method = "bray")
Heatmap(data,
row_names_side = "left",
row_dend_side = "left",
column_names_side = "bottom",
row_names_gp = gpar(cex=fontsize, fontface = "bold"),
column_names_gp = gpar(cex=0.9, fontface = "bold"),
row_dend_width = unit(4, "cm"),
column_dend_height = unit(3, "cm"),
rect_gp = gpar(col = "grey"),
column_title = "Year/Season",
column_names_rot = 35,
row_title = "Site",
clustering_distance_rows = d1,
clustering_distance_columns = d2,
clustering_method_rows = "ward.D2",
clustering_method_columns = "ward.D2",
row_km = 3,
column_km = 4
)
您应该首先定义一个用于 Bray-Curtis 距离计算的函数 (bray_dist
)。
然后,你设置 clustering_distance_rows=bray_dist
和
clustering_distance_rows=bray_dist
在 Heatmap
.
library(vegan)
library(ComplexHeatmap)
set.seed(1234)
data <- matrix(rpois(30,0.9),ncol=6, nrow=5)
colnames(data) <- c("2004W", "2004D", "2005W", "2005D", "2006W", "2006D")
fontsize <- 8
bray_dist <- function(x) {
vegdist(log(x+1), method = "bray")
}
Heatmap(data, row_names_side = "left", column_names_side = "bottom",
row_dend_side = "left", rect_gp = gpar(col = "grey"),
row_names_gp = gpar(cex=fontsize, fontface = "bold"),
column_names_gp = gpar(cex=0.9, fontface = "bold"),
row_dend_width = unit(4, "cm"), column_dend_height = unit(3, "cm"),
column_title = "Year/Season", column_names_rot = 35, row_title = "Site",
clustering_distance_rows = bray_dist, clustering_distance_columns = bray_dist,
clustering_method_rows = "ward.D2", clustering_method_columns = "ward.D2",
row_km = 3, column_km = 4)
我在 R 中使用 Complexheatmap 函数(或“热图”),想知道是否有一种方法可以使用 Bray-Curtis 方法计算 col/row 距离(使用 ward.D2 聚类方法) 因为它不是 Complexheatmap 中支持的方法。不幸的是,我需要使用这个函数而不是 heatmap.2 和 pheatmap。
这是一些虚构的鱼类计数数据(我的实际数据有 47 个站点(行)和 32 个季节,但我不确定如何在此处重新创建):
data<-matrix(rpois(30,0.9),ncol=6, nrow=5)
colnames(data) <- c("2004W", "2004D", "2005W", "2005D", "2006W", "2006D")
# I tried assigning the method this way:
d1 <- vegdist(log(data+1), method = "bray")
d2 <- vegdist(t(log(data+1)), method = "bray")
Heatmap(data,
row_names_side = "left",
row_dend_side = "left",
column_names_side = "bottom",
row_names_gp = gpar(cex=fontsize, fontface = "bold"),
column_names_gp = gpar(cex=0.9, fontface = "bold"),
row_dend_width = unit(4, "cm"),
column_dend_height = unit(3, "cm"),
rect_gp = gpar(col = "grey"),
column_title = "Year/Season",
column_names_rot = 35,
row_title = "Site",
clustering_distance_rows = d1,
clustering_distance_columns = d2,
clustering_method_rows = "ward.D2",
clustering_method_columns = "ward.D2",
row_km = 3,
column_km = 4
)
您应该首先定义一个用于 Bray-Curtis 距离计算的函数 (bray_dist
)。
然后,你设置 clustering_distance_rows=bray_dist
和
clustering_distance_rows=bray_dist
在 Heatmap
.
library(vegan)
library(ComplexHeatmap)
set.seed(1234)
data <- matrix(rpois(30,0.9),ncol=6, nrow=5)
colnames(data) <- c("2004W", "2004D", "2005W", "2005D", "2006W", "2006D")
fontsize <- 8
bray_dist <- function(x) {
vegdist(log(x+1), method = "bray")
}
Heatmap(data, row_names_side = "left", column_names_side = "bottom",
row_dend_side = "left", rect_gp = gpar(col = "grey"),
row_names_gp = gpar(cex=fontsize, fontface = "bold"),
column_names_gp = gpar(cex=0.9, fontface = "bold"),
row_dend_width = unit(4, "cm"), column_dend_height = unit(3, "cm"),
column_title = "Year/Season", column_names_rot = 35, row_title = "Site",
clustering_distance_rows = bray_dist, clustering_distance_columns = bray_dist,
clustering_method_rows = "ward.D2", clustering_method_columns = "ward.D2",
row_km = 3, column_km = 4)