Complex Heatmap
1
1
Entering edit mode
6 weeks ago
arsa ▴ 20

I want to reorder the column clusters in the complex heatmap. For example: I want cluster 0, 1 ,3 ,2 and then 4, 5 and 6 in the heatmap. I am attaching my code and heatmap here. Please let me know how can I do that. The clusters are form Seurat object.

Below is my code and the heatmap that I want to reorder:

markers<- read.csv("markers.csv")
markers %>% group_by(cluster) %>% top_n(n = 15, wt = avg_log2FC) -> top15
toplot_gene<- top15$gene
mat<- combined[["RNA"]]@data[toplot_gene, ] %>% as.matrix()
mat<- t(scale(t(mat)))
head(mat)

cluster_anno<- combined@meta.data$seurat_clusters
head(combined@meta.data)

myCol <- colorRampPalette(c('dodgerblue', 'black', 'yellow'))(50)
myBreaks <- seq(-2, 2, length.out = 50)

Heatmap(mat, name = "Expression",  
        column_split = factor(cluster_anno),
        cluster_columns = TRUE,
        show_column_dend = FALSE,
        cluster_column_slices = TRUE,
        column_title_gp = gpar(fontsize = 8),
        column_gap = unit(0.5, "mm"),
        cluster_rows = FALSE,
        show_row_dend = FALSE,
        col = colorRamp2(myBreaks, myCol),
        row_names_gp = gpar(fontsize = 6),
        column_title_rot = 90,
        top_annotation = HeatmapAnnotation(foo = anno_block(gp = gpar(fill = scales::hue_pal()(9)))),
        show_column_names = FALSE,
        use_raster = TRUE)

enter image description here

ggplot2 R heatmap single-cell Seurat • 425 views
ADD COMMENT
2
Entering edit mode
6 weeks ago

Hi,

You need:

...,
column_split = factor(cluster_anno, levels = c(0,1,2,3,4,5,6)),
...,

Failing that, take a look at these two parameters:

cluster_columns = TRUE
cluster_column_slices = TRUE

Kind regards,

Kevin

ADD COMMENT
0
Entering edit mode

Hi Kevin,

Thanks for the reply. I could change the cluster order. Can you help me how can I reannotate the clusters now. I need to reannotate the column clusters instead of Seurat number clusters.

Thanks a lot!

ADD REPLY
0
Entering edit mode

Please show the code that you're running. I used the factor() approach just now in my own data, and it does work.

ADD REPLY
0

Login before adding your answer.

Traffic: 2598 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