ComplexHeatmap
ComplexHeatmap copied to clipboard
Re-order grouping in dendogram from cluster_within_group
I have an example where I have two annotations, called by a annotation_df (heatmap_annotation). Annotation 1 - "Cell_Type" - CellA, CellB, CellC Annotation 2 - "Condition" - Control vs. Treated
ha<- HeatmapAnnotation(df=heatmap_annotation[,c("Cell_Type", "Condition")],
col = list("Condition" = c("Control"="black", "Treated"="red"))
)
When plotting a heatmap, I use the cluster_within_group to create a dendogram, such that:
grouping <- as.factor(heatmap_annotation$"Cell_Type"
dend1 <- cluster_within_group(heatmap_data, grouping)
When plotting the resultant heatmap with
hm<-Heatmap(heatmap_data,
name = "Expression",
bottom_annotation = ha,
cluster_rows =F, cluster_columns=dend1,
column_split=heatmap_annotation$Cell_Type
)
The heatmap looks great, but due to the dendogram, I get a heatmap where red/black is not "ordered":
Is there a way to order the annotation grouping so that all the red ("Treated") or black ("Control") samples are on the right/left? I know that I can manually order ALL the columns, but I was wondering if there was an easy way to "flip" the dendogram of one of the Cell_Types
Apologize for not having example data, I couldn't make an easily reproducible example that would cluster in this way!