dendextend: color_branches not working for certain hclust methods
0
0
Entering edit mode
Zach Roe ▴ 10
@zach-roe-11189
Last seen 4.6 years ago

Hi,

I am using dendextend to plot hclust tree objects generated by each hclust method from hclust{stats}: "ward.D", "ward.D2", "single", "complete", "average" (= UPGMA), "mcquitty" (= WPGMA), "median" (= WPGMC) or "centroid" (= UPGMC).

I notice the color coding for color_branches fails when I use method = "median" or "centroid".

I tested it with randomly generated matrix and error is replicated for the "median" and "centroid" methods, is there a specific reason for this?

set.seed(1)
df <- as.data.frame(replicate(10, rnorm(20)))
df.names <- rep(c("black", "red", "blue", "green", "cyan"), 2)
df.col <- rep(c("black", "red", "blue", "green", "cyan"), 2)
colnames(df) <- df.names
df.dist <- dist(t(df), method = "euclidean")

# plotting works for "ward.D", "ward.D2", "single", "complete", "average", "mcquitty"
dend <- as.dendrogram(hclust(df.dist, method = "ward.D2"), labels = df.names)
labels_colors(dend) <- df.col[order.dendrogram(dend)]
dend.colorBranch <- color_branches(dend, k = length(df.names), col = df.col[order.dendrogram(dend)])
dend.colorBranch %>% set("branches_lwd", 3) %>% plot(horiz = TRUE)

# color_branches fails for "median" or "centroid"
dend <- as.dendrogram(hclust(df.dist, method = "median"), labels = df.names)
labels_colors(dend) <- df.col[order.dendrogram(dend)]
dend.colorBranch <- color_branches(dend, k = length(df.names), col = df.col[order.dendrogram(dend)])
dend.colorBranch %>% set("branches_lwd", 3) %>% plot(horiz = TRUE)

dend <- as.dendrogram(hclust(df.dist, method = "centroid"), labels = df.names)
labels_colors(dend) <- df.col[order.dendrogram(dend)]
dend.colorBranch <- color_branches(dend, k = length(df.names), col = df.col[order.dendrogram(dend)])
dend.colorBranch %>% set("branches_lwd", 3) %>% plot(horiz = TRUE)

 

Session Info below:

sessionInfo()

R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.3

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
 [1] parallel  stats4    grid      stats     graphics  grDevices utils     datasets  methods   base 

other attached packages:
 [1] hexbin_1.27.1              vsn_3.42.3                 DESeq2_1.14.1              SummarizedExperiment_1.4.0 BiocParallel_1.8.1        
 [6] arrayQualityMetrics_3.30.0 UniProt.ws_2.14.0          RCurl_1.95-4.8             bitops_1.0-6               RSQLite_1.1-2             
[11] HGNChelper_0.3.4           biomaRt_2.30.0             EnsDb.Hsapiens.v75_2.1.0   ensembldb_1.6.2            GenomicFeatures_1.26.2    
[16] GenomicRanges_1.26.2       GenomeInfoDb_1.10.3        org.Hs.eg.db_3.4.0         AnnotationDbi_1.36.2       IRanges_2.8.1             
[21] S4Vectors_0.12.1           Biobase_2.34.0             BiocGenerics_0.20.0        factoextra_1.0.4.999       FactoMineR_1.35           
[26] ggbiplot_0.55              scales_0.4.1               plyr_1.8.4                 devtools_1.12.0            calibrate_1.7.2           
[31] MASS_7.3-45                cluster_2.0.5              squash_1.0.7               ggdendro_0.1-20            xlsx_0.5.7                
[36] xlsxjars_0.6.1             rJava_0.9-8                gridExtra_2.2.1            dendextend_1.4.0           ggrepel_0.6.5             
[41] ggplot2_2.2.1              pheatmap_1.0.8             lattice_0.20-34            RColorBrewer_1.1-2         gplots_3.0.1              
[46] reshape2_1.4.2             reshape_0.8.6              tidyr_0.6.1                dplyr_0.5.0                circlize_0.3.9            
[51] migest_1.7.3  

 

dendextend • 1.6k views
ADD COMMENT
0
Entering edit mode

Apologies, I just realize dendextend is not a Bioconductor package, I cross-posted on stack overflow:

https://stackoverflow.com/questions/42406763/r-dendextend-color-branches-not-working-for-certain-hclust-methods

ADD REPLY

Login before adding your answer.

Traffic: 726 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6