五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

繪制單細(xì)胞分析組織中細(xì)胞數(shù)量和細(xì)胞比例柱狀圖

2023-04-03 09:20 作者:小云愛生信  | 我要投稿

爾云間? 一個專門做科研的團(tuán)隊

原創(chuàng)?小果?生信果


今天繪制一下單細(xì)胞分析結(jié)果組織中細(xì)胞數(shù)量和細(xì)胞比例柱狀圖:

1.?安裝需要的R包
install.packages(“Seurat”)
install.packages(“patchwork”)
install.packages(“reshape2”)
install.packages(“RcolorBrewer”)
install.packages(“scales”)
install.packages(“ggplot2”)
install.packages(“tidyverse”)


2.?導(dǎo)入所需要的R包
library(Seurat)
library(patchwork)
library(reshape2)
library(RcolorBrewer)
library(ggplot2)
library(tidyverse)
library(scales)


3.?代碼展示

數(shù)據(jù)下載

wget?https://cf.10xgenomics.com/samples/cell/pbmc3k/pbmc3k_filtered_gene_bc_matrices.tar.gz


tar -zxvf pbmc3k_filtered_gene_bc_matrices.tar.gz
#分析所需要的文件三個在filtered_gene_bc_matrices/hg19/


pbmc.data <- Read10X(data.dir = "filtered_gene_bc_matrices/hg19/")
# Initialize the Seurat object with the raw (non-normalized data).
pbmc <- CreateSeuratObject(counts = pbmc.data, project = "pbmc3k", min.cells = 3, min.features = 200)
# Normalizing the data
pbmc <- NormalizeData(pbmc, normalization.method = "LogNormalize", scale.factor = 10000)
#Identification of highly variable features
pbmc <- FindVariableFeatures(pbmc, selection.method = "vst", nfeatures = 2000)
all.genes <- rownames(pbmc)
pbmc <- ScaleData(pbmc, features = all.genes)
#Run non-linear dimensional reduction (UMAP/tSNE)
pbmc <- RunUMAP(pbmc, dims = 1:10)

#開始繪圖
colourCount = length(unique(pbmc@meta.data$celltype))
getPalette = colorRampPalette(brewer.pal(9, "Set1"))
celltype_colors <- getPalette(colourCount)

#提取樣本和細(xì)胞數(shù)據(jù),并且進(jìn)行長寬數(shù)據(jù)轉(zhuǎn)換
plotC <- table(pbmc@meta.data$sample, pbmc@meta.data$celltype) %>% melt()
colnames(plotC) <- c("Sample", "CellType","Number")

#繪制每個組織中細(xì)胞數(shù)目柱狀圖
pC1 <- ggplot(data = data_plotC, aes(x = Sample, y = Number, fill = CellType)) +
? geom_bar(stat = "identity", width=0.8,aes(group=CellType),position="stack")+
? scale_fill_manual(values=celltype_colors) +
? theme_bw()+
? theme(panel.grid =element_blank()) +
? labs(x="",y="Average number")+
? theme(axis.text = element_text(size=12, colour = "black"))+
? theme(axis.title.y = element_text(size=12, colour = "black"))+
? theme(panel.border = element_rect(size = 1, linetype = "solid", colour = "black"))+
? theme(axis.text.x = element_text(angle = 45,hjust = 0.8,? vjust = 0.6))

#繪制每個組織中細(xì)胞比例柱狀圖
pC2 <- ggplot(data = plotC, aes(x = Sample, y = Number, fill = CellType)) +
? geom_bar(stat = "identity", width=0.8,aes(group=CellType),position="fill")+
? scale_fill_manual(values=celltype_colors) +
? theme_bw()+
? theme(panel.grid =element_blank()) +
? labs(x="",y="Cell proportion")+
? scale_y_continuous(labels = percent)+? ####用來將y軸移動位置
? theme(axis.text = element_text(size=12, colour = "black"))+
? theme(axis.title.y = element_text(size=12, colour = "black"))+
? theme(panel.border = element_rect(size = 1, linetype = "solid", colour = "black"))+
? theme(axis.text.x = element_text(angle = 45,hjust = 0.8,? vjust = 0.6))#讓橫軸上的標(biāo)簽傾斜45度

#兩個圖片進(jìn)行拼圖
pC <- pC1 + pC2 + plot_layout(ncol = 2, widths = c(1,1),guides = 'collect')

#保存圖片
ggsave(pC,file="plotC.pdf",width = 7, height = 5)




推薦閱讀


關(guān)注小果,小果將會持續(xù)為你帶來更多生信干貨哦。

生信果

生信入門、R語言、生信圖解讀與繪制、軟件操作、代碼復(fù)現(xiàn)、生信硬核知識技能、服務(wù)器等

原創(chuàng)內(nèi)容





繪制單細(xì)胞分析組織中細(xì)胞數(shù)量和細(xì)胞比例柱狀圖的評論 (共 條)

分享到微博請遵守國家法律
漳平市| 泰州市| 石台县| 宁陵县| 衢州市| 淮北市| 普陀区| 卓尼县| 沛县| 安新县| 广昌县| 庄河市| 浦县| 施甸县| 诸暨市| 德化县| 无棣县| 桐庐县| 新河县| 来宾市| 宝山区| 孝义市| 广东省| 石楼县| 韶关市| 彭水| 天长市| 嵊州市| 扶余县| 马公市| 陆川县| 乐安县| 嵩明县| 图木舒克市| 习水县| 毕节市| 宝丰县| 专栏| 长岛县| 常山县| 疏附县|