空间转录组 单细胞

10X空间转录组之绘图小细节分享

2022-06-06  本文已影响0人  单细胞空间交响乐

新的一周第一天,我们不整那些难的,来点小的绘图细节分析,如下图

图片.png

这个图包括两部分,左图的画法很简单

SpatialFeaturePlot(st_se, features = "Macrophage", pt.size.factor = 1,
                   crop = FALSE, alpha = c(0.1,1), min.cutoff = 0, max.cutoff = 1)

这是只是需要设置一下alpha参数,就可以把没有该细胞类型的位置给暴露出来。

关键是右边部分,其中st_pbs是包含预测的细胞类型分数矩阵的rds、Zone是空间聚类信息

zone_cell_avgs_pbs <- AverageExpression(st_pbs, assays = 'predictions', group.by = c('Zone', 'orig.ident'), slot = 'data') %>% as.data.frame()
zone_cell_avgs_pbs_melted <- zone_cell_avgs_pbs %>% melt()
zone_cell_avgs_pbs_melted$Celltype <- rep(rownames(zone_cell_avgs_pbs),12)
zone_cell_avgs_pbs_melted$Zone <- c(rep('Defect', 96), rep('IntactMuscle', 96), rep('Transition', 96))
zone_cell_avgs_pbs_melted$Tissue <- rep(c(rep('1197L', 24), rep('1203L', 24), rep('599L', 24), rep('600R', 24)), 3)
write.csv(zone_cell_avgs_pbs_melted, file = 'Data/PBS_Zone_Celltype_Averages.csv')

p <- zone_cell_avgs_pbs_melted %>% 
  filter(Celltype == 'Macrophage') %>%
  ggplot(aes(x=Zone, y=value, fill=Zone)) + 
  stat_summary(fun.data="mean_se", geom="errorbar", width=0.5) +
  stat_summary(fun="mean", geom="crossbar", aes(fill=Zone)) +
  geom_point(aes(fill=Zone),size=4,shape=21, position = position_dodge(0.2)) +
  labs(x="", y="Average Prediction Score") +
  theme_classic() +
  scale_x_discrete(limits = c("Defect", "Transition", "IntactMuscle")) +
  scale_y_continuous(expand=c(0,0)) +
  coord_cartesian(ylim=c(0,0.8)) +
  stat_compare_means(comparisons = 
                       list(c("Defect", "Transition"), 
                            c("Transition", "IntactMuscle"),
                            c("Defect", "IntactMuscle")), 
                     bracket.size = 1, 
                     method = "t.test", paired = TRUE,
                     method.args = c(var.equal = FALSE), 
                     label = "p.signif", size = 8) +
  theme(axis.title.y = element_text(size = 20, face = "plain", color = "black")) +
  theme(axis.text.y = element_text(size = 15, color = "black")) +
  theme(axis.text.x = element_text(size = 20, colour = "black")) +
  theme(legend.position="none") +
  rotate_x_text(angle = 45)

print(p)

然后,大功告成了,

图片.png

生活很好,有你更好

上一篇 下一篇

猜你喜欢

热点阅读