Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CNS绘图复现:单细胞数据的marker基因分析(点矩阵图-dotplot) #5851

Closed
ixxmu opened this issue Oct 31, 2024 · 1 comment
Closed

Comments

@ixxmu
Copy link
Owner

ixxmu commented Oct 31, 2024

https://mp.weixin.qq.com/s/iYesDF_ZkNkqUIKBJanLSA

@ixxmu
Copy link
Owner Author

ixxmu commented Oct 31, 2024

CNS绘图复现:单细胞数据的marker基因分析(点矩阵图-dotplot) by R语言生信医学统计与科研

一、引言

在前面几个章节中,我们介绍了单细胞数据分析的各种技术文档,既有单细胞数据分析的常规流程,也有部分的高级分析。现在我们来讨论一下,除了基本的绘图之外,那些比较高级的CNS绘图。

比如:2022年发表于Nature中的marker基因分析

二、实操

2.1 安装高级分析的软件

# install.packages("devtools")devtools::install_github("junjunlab/jjAnno")


2.2 加载数据

本案例主要是基于单细胞数据的marker基因,绘制CNS级别的表达情况。

# load datadot_data <- read.delim('marker-genes.txt',header = T) %>%  arrange(class)
> head(dot_data,3)              cell  gene            class mean.expression percentage1 1b CoelEpi GATA4 DMRT1 Early supporting       0.3749122   36.036142 1b CoelEpi GATA4  CPA2 Early supporting       0.7495705   95.822353 1b CoelEpi GATA4 GPR37 Early supporting       0.1604790   95.79420> unique(dot_data$cell)[1] "1b CoelEpi GATA4" "2a Early somatic" "2b ESGC male"     "2b ESGC female"   "2c PreGC-I"      [6] "2d Sertoil"       "3a Early sPAX8"   "3b Gi" 
# add cell groupdot_data$cellGroup <- case_when(  dot_data$cell %in% c("1b CoelEpi GATA4", "2a Early somatic", "2b ESGC male") ~ "cell type1",  dot_data$cell %in% c("2b ESGC female", "2c PreGC-I", "2d Sertoil")  ~ "cell type2",  dot_data$cell %in% c("3a Early sPAX8", "3b Gi")  ~ "cell type3")
> head(dot_data, 3)              cell  gene            class mean.expression percentage  cellGroup1 1b CoelEpi GATA4 DMRT1 Early supporting       0.3749122   36.03614 cell type12 1b CoelEpi GATA4  CPA2 Early supporting       0.7495705   95.82235 cell type13 1b CoelEpi GATA4 GPR37 Early supporting       0.1604790   95.79420 cell type1


2.3 基础绘图

# 将基因按照细胞类型进行排序dot_data$gene <- factor(dot_data$gene,levels = unique(dot_data$gene))# plotpdot <-  ggplot(dot_data,aes(x = gene,y = cell)) +  geom_point(aes(fill = mean.expression,size = percentage),             color = 'black',             shape = 21) +  theme_bw(base_size = 14) +  xlab('') + ylab('') +  scale_fill_gradient2(low = 'white',mid = '#EB1D36',high = '#990000',                       midpoint = 0.5,                       limits = c(0,1),                       breaks = seq(0,1,0.5),                       labels = seq(0,1, 0.5),                       name = 'Mean expression') +  scale_size(range = c(1,6),              limits = c(0, 100),             breaks = seq(20,100,20),              labels = seq(20,100,20)  ) +  theme(panel.grid = element_blank(),        axis.text = element_text(color = 'black'),        aspect.ratio = 0.5,        plot.margin = margin(t = 1,r = 1,b = 1,l = 1,unit = 'cm'),        axis.text.x = element_text(angle = 90,hjust = 1,vjust = 0.5,                                   face = 'italic'),                                   axis.text.y = element_text(color = 1:8)  ) +  coord_cartesian(clip = 'off') +  guides(    fill = guide_colorbar(      direction = "horizontal",      title.position = "top",      barwidth = unit(5, "cm")    ),    size = guide_legend(      title = "Percent of cells",      direction = "horizontal",      title.position = "top",      label.position = "bottom",      override.aes = list(        color = "black",        fill = "grey"      )    )  )
pdot

2.4 个性化设置

# add segmentP1 <- annoSegment(object = pdot,                  annoPos = 'top', # 将注释条,添加到顶部                  xPosition = c(1:21), # 注释条的x轴的位置                  yPosition = 8.8, # 注释条的y轴位置,需要多次个性化调整                  segWidth = 0.7, # 注释条的宽度,需要多次个性化调整                  pCol = c(useMyCol('stallion',20),'orange') # 注释条的颜色                  )

# add rect1P2 <- annoRect(object = P1, annoPos = 'left', # 添加方框的位置 annoManual = T, # 可以手动设置 # 设置方框的位置,由于刻度是整数,从下往上依次是1,2,3,4 # 所以设置方框的位置是0.5,1.5,等,上下包含要框的内容 # list 表示添加控件的个数,比如下面表示添加 [0.5,4.5]和[4.5,8.5] yPosition = list(c(0.5,4.5), c(4.5,8.5)), # 个性化多次调整,多尝试,找一个合适的数据值 xPosition = c(-6.5,0.3), pCol = rep('white',2), # 边框颜色 pFill = useMyCol('calm',2), # 填充颜色 alpha = 0.5 # 填充颜色透明度 )
# add rect2P3 <- annoRect(object = P2, annoPos = 'left', annoManual = T, yPosition = c(2.5,6.5), xPosition = c(-6.5,16.5), pCol = 'black', pFill = 'transparent', lty = 'dashed', lwd = 3)

# add rect4P4 <- annoRect(object = P3, annoPos = 'left', annoManual = T, yPosition = c(3.5, 4.5), xPosition = c(6.5,7.5), pCol = 'blue', pFill = 'transparent', lty = 1, lwd = 3)
# add branchP5 <- annoSegment(object = P4, annoPos = 'top', # 表示自动映射,这是一种比较友好的方式, # 否则需要人为核查,还容易出现错误 aesGroup = T, # 自动映射的分组信息列 aesGroName = 'class', yPosition = 9.2, segWidth = 0.5, addBranch = T, # 添加树状分支 addText = T, textRot = 45, # 字体颜色,可以更具图片的顺序,调整颜色 textCol = c(rep("black", 3),"blue", rep("black", 7)),                  # 字体的对其方式 hjust = 0, vjust = 0,                  lwd = 2, # 分支的线型 branDirection = -1, # 分支向下                  pCol = rep('black',11)) # 分支颜色


@ixxmu ixxmu changed the title archive_request CNS绘图复现:单细胞数据的marker基因分析(点矩阵图-dotplot) Oct 31, 2024
@ixxmu ixxmu closed this as completed Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant