单细胞-第四节 多样本数据分析,下游画图

文件在单细胞\5_GC_py\1_single_cell\2_plots.Rmd

1.细胞数量条形图

c 复制代码
rm(list = ls())
library(Seurat)
load("seu.obj.Rdata")

dat = as.data.frame(table(Idents(seu.obj)))
dat$label = paste(dat$Var1,dat$Freq,sep = ":")
head(dat)
library(ggplot2)
library(paletteer)
#View(palettes_d_names)
ggplot(dat,aes(x = Freq,fill = Var1,y = Var1))+
  scale_fill_paletteer_d("ggsci::category20_d3")+
  geom_bar(stat = "identity")+
  theme_bw()+
  geom_text(aes(x = 0,label = label),hjust = 0)+
  theme(axis.text.y = element_blank(),   # 隐藏纵坐标刻度文字
        axis.ticks.y = element_blank(),
        axis.title.y = element_blank())  # 隐藏纵坐标刻度线

2.细胞比例条形图

c 复制代码
seu.obj$seurat_annotation = [email protected]
ggplot([email protected],aes(orig.ident,fill = seurat_annotation))+
  geom_bar(position = "fill", alpha = 0.9,width = 0.5)+
  scale_fill_paletteer_d("ggsci::category20_d3")+
  theme_classic()+
  coord_flip()+
  coord_fixed(ratio = 4) #纵轴长度是横轴的4倍

3.小提琴图

c 复制代码
load("markers.Rdata")
library(tidyverse)
g = allmarkers %>% group_by(cluster) %>% top_n(1,wt = avg_log2FC) %>% pull(gene)

m = as.matrix(seu.obj@assays$RNA@layers$data)
rownames(m) = Features(seu.obj)
colnames(m) = Cells(seu.obj)
vln.df <- m %>%
  t() %>%
  as.data.frame()%>%
  select(g) %>% 
  rownames_to_column("CB") %>% 
  mutate(cluster = seu.obj$seurat_annotation)%>%
  pivot_longer(cols = 2:(ncol(.)-1),#宽边长
               names_to = "gene",
               values_to = "exp") %>% 
  mutate(gene = factor(gene,levels = g))
head(vln.df)
c 复制代码
# 自定义颜色
library(paletteer)
my_color = paletteer_d(`"ggsci::category20_d3"`)
my_color = colorRampPalette(my_color)(length(unique(vln.df$cluster)))
# 画图
p1 <- ggplot(vln.df,aes(exp,cluster),color=factor(cluster))+
  geom_violin(aes(fill=cluster),scale = "width")+
  scale_fill_manual(values = my_color)+
  facet_grid(.~gene,scales = "free_y", switch = "x")+
  scale_x_continuous(expand = c(0,0),position = "top")+
  theme_bw()+
  theme(
    panel.grid = element_blank(),
    axis.title.x.top = element_blank(),
    #axis.ticks.x.bottom = element_blank(),
    axis.text.x.top= element_text(hjust = 1,vjust = NULL,color = "black",size = 7),
    #axis.title.y.left = element_blank(),
    #axis.ticks.y.left = element_blank(),
    #axis.text.y.left = element_blank(),
    legend.position = "none",
    panel.spacing.y = unit(0, "cm"),
    strip.text.y = element_text(angle=0,size = 14,hjust = 0),
    strip.background.y = element_blank()
  )
p1

4.气泡图

c 复制代码
g = allmarkers %>% group_by(cluster) %>% top_n(5,wt = avg_log2FC) %>% pull(gene) %>% unique()
DotPlot(seu.obj,features = g,cols = "RdYlBu")+RotatedAxis()

5.GC基因韦恩图

c 复制代码
f = read.delim("gcgene.txt",header = F)
k = allmarkers$p_val_adj<0.05 & allmarkers$avg_log2FC>2
table(k)
g = intersect(allmarkers$gene[k],f$V1)
save(g,file = "g.Rdata")
library(tinyarray)
draw_venn(list(pyroptosis = f$V1,
               marker = unique(allmarkers$gene[k])),"")
ggsave("venn.png")
c 复制代码
m = as.matrix(seu.obj@assays$RNA@layers$data)
rownames(m) = Features(seu.obj)
colnames(m) = Cells(seu.obj)
m = m[g,]
ac = data.frame(row.names = colnames(m),
                celltype = Idents(seu.obj))
library(dplyr)
ac = arrange(ac,celltype)
m = m[,rownames(ac)]
pheatmap::pheatmap(m,show_colnames = F,cluster_cols = F,cluster_rows = F,scale = "row",breaks = seq(-1.6,3,length.out = 100),annotation_col = ac)

6.差异焦亡基因富集分析

c 复制代码
e = quick_enrich(g,destdir = tempdir())
e[[4]]+e[[3]]
相关推荐
lilye661 小时前
精益数据分析(10/126):深度剖析数据指标,驱动创业决策
大数据·人工智能·数据分析
liqingdi4373 小时前
WSL+Ubuntu+miniconda环境配置
linux·windows·ubuntu
小研学术9 小时前
如何用AI辅助数据分析及工具推荐
论文阅读·人工智能·ai·数据挖掘·数据分析·deepseek
qq_436962189 小时前
AI数据分析与BI可视化结合:解锁企业决策新境界
人工智能·数据挖掘·数据分析
sky.fly9 小时前
多路由器通过RIP动态路由实现通讯(单臂路由)
网络·windows·智能路由器
lilye6610 小时前
精益数据分析(11/126):辨别虚荣指标,挖掘数据真价值
大数据·人工智能·数据分析
扛枪的书生10 小时前
Windows 身份验证协议
windows
赵钰老师11 小时前
【大语言模型DeepSeek+ChatGPT+python】最新AI-Python机器学习与深度学习技术在植被参数反演中的核心技术应用
人工智能·arcgis·语言模型·chatgpt·数据分析
sevevty-seven13 小时前
解决 Arduino IDE 2.3.6 在 Windows 上无法启动:缺少 Documents 文件夹与注册表路径错误
ide·windows·stm32
虾球xz15 小时前
游戏引擎学习第235天:在 Windows 上初始化 OpenGL
windows·学习·游戏引擎