因为Dotplot只能看几个基因在不同的annotation下的点图,我想要看单个基因在不同的组织下的不同annation下的表达分布,其实就是FeaturePlot的量化。
思路就是将x轴的基因替换成不同的组织。
![](https://i-blog.csdnimg.cn/blog_migrate/ebcbd9e4dd3af26165f6b05db9337d50.png)
#####第二个方法,增加一个tissue_annotation 的metadata 然后再将一列拆分成六列
##添加一个tissue_annotation的列
tissue_annotation <- paste0(fca_all_seurat@meta.data[["tissue"]], "_", fca_all_seurat@meta.data[["annotation_broad_extrapolated"]])
fca_all_seurat@meta.data[["tissue_annotation"]] <- tissue_annotation
##获取dotplot的数据
dotplot_data_all_SIFa_tissue_annotation <- DotPlot(fca_all_seurat, features = 'SIFa', group.by = 'tissue_annotation')$data
##删除percentage = 0的数据
delete <- c()
for (i in c(1:255)) {
if (dotplot_data_all_SIFa_tissue_annotation[i,3] == 'fat') {
dotplot_data_all_SIFa_tissue_annotation[i,3] <- 'fat_body'
}
if (dotplot_data_all_SIFa_tissue_annotation[i,2] == 0) {
delete <- c(delete, i)
}
}
# install.packages("stringr")
library(stringr)
dotplot_data_all_SIFa_tissue_annotation$features.plot <- str_extract(dotplot_data_all_SIFa_tissue_annotation$id,'[a-z]{1,10}')
dotplot_data_all_SIFa_tissue_annotation <- dotplot_data_all_SIFa_tissue_annotation[-delete,]
a <- str_extract(dotplot_data_all_SIFa_tissue_annotation$id,'([a-z]+)$')
b <- str_extract(dotplot_data_all_SIFa_tissue_annotation$id,'([a-z]+) ([a-z]+)$')
c <- str_extract(dotplot_data_all_SIFa_tissue_annotation$id,'([a-z]+) ([a-z]+) ([a-z]+)$')
for (i in c(1:length(a))) {
if (!is.na(c[i])) {
a[i] <- c[i]
}
else if (!is.na(b[i])) {
a[i] <- b[i]
}
}
dotplot_data_all_SIFa_tissue_annotation$id <- a
##绘图
ggplot(dotplot_data_all_SIFa_tissue_annotation,aes(x=features.plot,y = id,size = pct.exp, color = avg.exp.scaled))+
geom_point() +
scale_size("Percent\nExpressed", range = c(0,15)) +
scale_y_discrete(position = "left") +
scale_color_gradientn(colours = brewer.pal(5, "Reds"),
guide = guide_colorbar(ticks.colour = "black",frame.colour = "black"),
name = "Average\nexpression") +
cowplot::theme_cowplot() +
ylab("Identity") + xlab("Features") +
theme_bw(base_rect_size = 2, base_line_size = 1) +
theme(
axis.text.x = element_text(size=10, angle=0, hjust=0.5, color="black", lineheight = 10, face = 2),
axis.text.y = element_text(size=12, color="black", face = 2),
axis.title = element_text(size=14, face = 2),
)