I would use data
from Seurat object and perform a Hierarchical Clustering
using Complexheatmap
.
library(Seurat)
library(SeuratData)
library(dplyr)
library(ComplexHeatmap)
data=UpdateSeuratObject(pbmc3k.final)
all.markers=FindAllMarkers(object=data)
all.markers %>%
group_by(cluster) %>%
dplyr::filter(avg_log2FC > 1 & p_val_adj < 0.05) %>%
slice_head(n = 10) %>%
ungroup() -> top10
head(top10)
mat<- data[["RNA"]]@data[c(top10$gene), ] %>% as.matrix()
mat[1:5, 1:5]
## scale the rows
mat<- t(scale(t(mat)))
mat[1:5, 1:5]
cluster_anno<- data@meta.data$seurat_annotations
quantile(mat, c(0.1, 0.95))
Seurat::PurpleAndYellow()
## make the black color map to 0. the yellow map to highest and the purle map to the lowest
col_fun = circlize::colorRamp2(c(-1, 0, 2), c("#FF00FF", "black", "#FFFF00"))
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 = TRUE,
show_row_dend = FALSE,
col = col_fun,
row_names_gp = gpar(fontsize = 4),
column_title_rot = 90,
top_annotation = HeatmapAnnotation(foo = anno_block(gp = gpar(fill = scales::hue_pal()(9)))),
show_column_names = FALSE,
use_raster = TRUE,
raster_quality = 4)
Thanks for the help, much appreciated!
use the data slot, and as shown in the code, you then scale it by yourself.