国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

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

分享到微博請遵守國家法律
曲麻莱县| 玉树县| 黔西县| 徐闻县| 九寨沟县| 织金县| 鸡泽县| 洞口县| 梅州市| 那曲县| 敦煌市| 澄江县| 西畴县| 浪卡子县| 渭南市| 张家口市| 陵川县| 昆明市| 黑水县| 红安县| 米易县| 桑植县| 连江县| 新巴尔虎右旗| 南川市| 西丰县| 敦煌市| 麟游县| 栾川县| 陈巴尔虎旗| 南丰县| 曲阳县| 六盘水市| 宾阳县| 安图县| 凯里市| 株洲市| 高安市| 凤翔县| 宁远县| 孙吴县|