Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract order of clustered column #100

Open
chrismahony opened this issue Mar 5, 2024 · 1 comment
Open

extract order of clustered column #100

chrismahony opened this issue Mar 5, 2024 · 1 comment

Comments

@chrismahony
Copy link

I have created my pheatmap using:

p<-pheatmap(mat),
scale = "row",
show_rownames = T, show_colnames = T,
border_color = NA,
clustering_method = "average",
clustering_distance_rows = "correlation",
clustering_distance_cols = "correlation",
breaks = seq(-3, 3, 0.05),
color = colorRampPalette(c("purple3", "black", "yellow2"))(120),
annotation_col =
pData(target_demoData)[, c("Annotation_initial2", "Conditon2")] )
p

How can I extract the clustering order of the column of my samples? Essentially I have >100 samples and pheatmap nicely clusters them in to 2 broad groups, how can I extract the plotting order for downstream analysis?

When I examine p there does not seem to be this data in the object,
thanks

@AlexWeinreb
Copy link

As ?pheatmap indicates in the "Value" section, p contains a list with a component tree_row, which is "the clustering of rows as hclust object". You can get more details in the "Value" section of ?hclust, notably:

order
a vector giving the permutation of the original observations suitable for plotting, in the sense that a cluster plot using this ordering and matrix merge will not have crossings of the branches.

So the exact order is available with:

p$tree_col$order

or if you want the labels in their clustered order:

p$tree_col$labels[p$tree_col$order]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants