按cluster分组展示marker基因的avg_log2FC差异倍数情况
jitMarkerplt <- function(df,score="avg_log2FC",group="cluster",symbol="gene"){
library(dplyr);library(ggplot2);library(BuenColors)
df[,group] <- factor(df[,group], levels = sort(names(table(df[,group]))) ) # 重新排序因子,决定坐标轴出图顺序
if ( sum(!is.na(as.numeric(names(table(df[,group]))))) != 0 ){
df[,group] <- factor(df[,group], levels = sort(as.numeric(names(table(df[,group])))) )
}else{
df[,group] <- factor(df[,group], levels = sort(names(table(df[,group]))) )
}
top10 <- df %>% group_by(!!group) %>% top_n(n = 10, wt = !!score) %>% data.frame()
p <- ggplot(df,aes_string(x = group, y = score)) +
geom_col(data=data.frame(table(df[,group])),aes(x=Var1,y=max(df[,score])+0.5),fill="#FFFFFF",alpha=0.5,color="black")+
geom_jitter(aes(x = df[,group], y = df[,score], color = df[,score]), size=1, alpha=1)+
scale_colour_gradientn(colours = jdb_palette("solar_extra"))+
#点注释
ggrepel::geom_text_repel(data = top10,aes(x = top10[,group], y = top10[,score], label = top10[,symbol]),
position=position_dodge(width=0.5),check_overlap = FALSE,
vjust='inward',hjust='inward',angle=0,size=2) +
guides(colour = guide_colourbar(title.vjust = 0.8))+
labs(color = score)+
geom_tile(data=data.frame(table(df[,group])),aes(x=Var1,y = 0.2,fill=Var1),width=0.8,height=0.15,color="grey",show.legend = F)+
geom_text(data=data.frame(table(df[,group])),aes(x=Var1,y = 0.2,label=Var1))+
scale_y_continuous(limits = c(0, max(df[,score])+0.6))+
labs(title = "New plot title")+
theme_minimal()+
theme(
plot.title = element_text(size = 12, face = "bold",vjust =0.5),
axis.line.y = element_line(),
axis.ticks.y = element_line(),
panel.grid = element_blank(),
legend.position = 'top',
legend.justification = c(1,0.5),
# legend.direction = "vertical",
axis.text.x = element_blank(),
panel.background = element_rect(colour = "black", size=2)
)+
labs(x=group,y=score)
return(p)
}
scRNA@misc$seucluster_markers_all <- Seurat::FindAllMarkers(object = scRNA, min.pct = 0.25,only.pos = T,logfc.threshold = 1, verbose = F)
jitMarkerplt (df=scRNA@misc$seucluster_markers_all)
网友评论