Closed kaizen89 closed 1 year ago
Hello! Thanks for the reply in the utilization of HGC. And here is the response for the two problems:
@zouzh14
@zouzh14 I had the same problem once; I did in this way:
hc <- HGC.dendrogram(G)
# First 2000 nodes from root
dend1 <- cut(as.dendrogram(hc), rev(hc$height)[2000])$upper # may take some time for large hclust
# Subtree
dend2 <- as.dendrogram(hc)[[1]][[2]][[1]]
Here dend1
and dend2
are dendrogram
objects, you can plot them directly with plot()
To set custom branch color, you can use color_branches
from the dendextend
package before plot
ting
plot(color_branches(dend, k=3, col=c("#FF0000","green","#0000FF")))
Otherwise, you can use the ggtree package, which provides highly customizable styles for your tree.
@Fan-iX, Thanks for sharing you experience!
HGC ploting function is based on the dendextend
package, so for the two requirements, I will show the solutions from dendextend.
We could save the tree to a dendextend object and setting colours, and in fact it is the way we do in PlotDendrogram
function. Here is an instance.
Pollen.ClusteringTree <- HGC.dendrogram(G = Pollen.SNN)
Pollen.ClusteringTree$height = log(Pollen.ClusteringTree$height + 1)
Pollen.ClusteringTree$height = log(Pollen.ClusteringTree$height + 1)
library(dplyr)
library(dendextend)
clus.dendrogram <- stats::as.dendrogram(Pollen.ClusteringTree)
dend <- clus.dendrogram %>%
dendextend::set("branches_k_color", k=5, value = c("skyblue", "orange", "grey", "pink", "firebrick")) %>%
dendextend::set("branches_lwd", 1.2) %>%
dendextend::set("labels_colors", "white")
plot(dend)
Here we set branches colours in "value" of dendextend::set("branches_k_color") sentence. You can find more example in https://cran.r-project.org/web/packages/dendextend/vignettes/dendextend.html.
With the function get_subdendrograms from dendextend
package, we can get the subtree with specific clustering numbers, and then choose the one wanted.
dend_list <- get_subdendrograms(dend, 5)
dend1 = dend_list[[1]]
plot(dend1)
Here the dend1 is the subtree in correspondence with "cluster 1" in dendextend::cutree(dend, k=5). More details could check https://www.rdocumentation.org/packages/dendextend/versions/1.15.2/topics/get_subdendrograms.
Thanks all!
Hi, I got a tree using seurat graph, now I would like to plot only a subset of it so it does not take a lot of time. Is it possible to do so? Also, how can I use a custom color palette instead of the default one which is not really convenient? Thanks!