Seurat绘制单个基因Cross Tissue和annotation的Dotplot

因为Dotplot只能看几个基因在不同的annotation下的点图,我想要看单个基因在不同的组织下的不同annation下的表达分布,其实就是FeaturePlot的量化。

思路就是将x轴的基因替换成不同的组织。

#####第二个方法,增加一个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),
  )
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值