ggplot画 ump 和tsne 从seurat中使用addmodule得到的umap 使用ggplot画图 subset_data
inflammatory_gene=read.xlsx(“G:/silicosis/sicosis/silicosis_ST/yll/0214/harmony_cluster/HALLMARK_INFLAMMATORY_RESPONSE.xlsx”)
head(inflammatory_gene)
inflammatory_gene=capitalize(tolower(inflammatory_gene$gene_symbol))
inflammatory_gene=list(inflammatory_gene)
load(file = “G:/silicosis/sicosis/yll/macrophage/no cluster2/macrophage_clean.rds”)
#对给定的基因集合进行打分
subset_data=AddModuleScore(subset_data,
features = inflammatory_gene,
name = “inflammatory_gene”)
Warning: The following features are not present in the object: Ccl20, Cxcl11, Cxcl6, Icoslg, Il4r, Cxcl8, Ros1, not searching for symbol synonyms
#结果保存在这里
colnames([email protected])
mydata<- FetchData(subset_data,vars = c(“UMAP_1”,“UMAP_2”,“inflammatory_gene1”,“stim”))
head(mydata)
a <- ggplot(mydata,aes(x = UMAP_1,y =UMAP_2,colour = inflammatory_gene1))+
geom_point(size = 1)+
scale_color_gradientn(values = seq(0,1,0.2),colours = c(‘blue’,‘cyan’,‘green’,‘yellow’,‘orange’,‘red’))
a+ theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = “black”))
mydata<- FetchData(subset_data,vars = c(“UMAP_1”,“UMAP_2”,“inflammatory_gene1”,“stim”,“cell.type”))
head(mydata)
class_avg <- mydata %>%
group_by(cell.type) %>%
summarise(
UMAP_1 = median(UMAP_1),
UMAP_2 = median(UMAP_2),
inflammatory_gene1=mean(inflammatory_gene1)
)
head(class_avg)
cell.type UMAP_1 UMAP_2 inflammatory_gene1
1 Macrophage-1 -3.66 -0.153 0.0131
2 Macrophage-2 11.2 1.77 0.0837
ggplot(mydata,aes(x = UMAP_1,y =UMAP_2,
colour = inflammatory_gene1))+geom_point(size = 1)+
scale_color_gradientn(values = seq(0,1,0.2),colours = c(‘blue’,‘cyan’,‘green’,‘yellow’,‘orange’,‘red’))+ #face = c(“plain”, “bold”, “italic”)
geom_text(aes(label = cell.type,fontface=“plain”,family=“sans”), data = class_avg,colour = “red”)+ # ggrepel::geom_text_repel(aes(label = cell.type), data = class_avg) +#添加标签
theme(text=element_text(family=“sans”,size=18)) +
facet_wrap(~stim)
getwd()
[1] “G:/silicosis/sicosis/silicosis_ST/yll/0214/harmony_cluster”