最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(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ì)胞比例柱狀圖的評論 (共 條)

分享到微博請遵守國家法律
永福县| 肇东市| 安吉县| 宣武区| 红桥区| 建瓯市| 福清市| 阿拉善右旗| 大理市| 赫章县| 合川市| 广东省| 漳平市| 闵行区| 平遥县| 青海省| 剑河县| 临沭县| 商都县| 碌曲县| 多伦县| 凤凰县| 娄烦县| 镇安县| 三明市| 天等县| 华坪县| 德庆县| 三明市| 浦北县| 北辰区| 延吉市| 兴仁县| 日喀则市| 莱州市| 紫阳县| 全椒县| 芦山县| 同江市| 茶陵县| 黄龙县|