Single cell seurat-cell proportion analysis-detailed drawing tutorial

Hello everyone, today we will draw the simplest cell proportion diagram of a single cell~

1. The old rule is to load pbmc data first

dir.create("~/gzh/细胞比例")
setwd("~/gzh/细胞比例")

subset_data=readRDS("~/gzh/pbmc3k_final.rds")
table(stringr::str_split(string = colnames(subset_data),pattern = "-",simplify = TRUE)[,2])subset_data$stim=ifelse(subset_data$nCount_RNA>2000,yes = "control",no = "exp")library(Seurat)library(ggplot2)

2. In order to draw the groups, add a column of group information to pbmc and look at the metadata information.

picture

If you don’t understand this step, you can watch my data structure video explanation, which will help you understand.

Single cell live broadcast - understanding seurat data structure and pbmc processing flow

Single cell live streaming three seurat data structure and data visualization

3. Sketch drawn

ggplot([email protected],        aes(x=Idents(subset_data), fill=stim)) + geom_bar(position = "fill")+RotatedAxis()

picture

4. Another kind of ggplot is better looking

ggplot([email protected],        aes(x=stim, fill=Idents(subset_data))) + geom_bar(position = "fill")+RotatedAxis()

picture

5 If you are still not satisfied, it is a matter of using ggplot2 to beautify the single-cell chart. Everyone can show their talents. I am here to give you some ideas.

method one

ggplot(subset_data@meta.data,  aes(x=stim, fill=Idents(subset_data))) + geom_bar(position = "fill")+RotatedAxis()+theme_classic()

picture

Method 2: Make the fonts on the horizontal and vertical axes of the graph clearer

gplot([email protected],        aes(x=stim, fill=Idents(subset_data))) + geom_bar(position = "fill")+  RotatedAxis()+theme_classic()+
theme(axis.text.x=element_text(angle=90,hjust = 1,vjust=0.5,                               size = 20),      axis.text.y=element_text(size = 19),      axis.text = element_text(color = 'black', size = 12))+ # scale_fill_gradient(low="red",high="blue")+  labs(x=NULL,y=NULL)

picture

For more beautiful pictures, you can follow my WeChat public account: Shengxin Little Doctor

 Single cell featureplot beautification modification-custom modification of picture style-umap density drawing contours

Guess you like

Origin blog.csdn.net/qq_52813185/article/details/134868188