ixxmu / mp_duty

抓取网络文章到github issues保存
https://archives.duty-machine.now.sh/
122 stars 30 forks source link

跟着Nature学作图 | 三维UMAP图 #5852

Closed ixxmu closed 1 week ago

ixxmu commented 1 week ago

https://mp.weixin.qq.com/s/-vuXRZ9ruVOQWxP6KPEZIQ

ixxmu commented 1 week ago

跟着Nature学作图 | 三维UMAP图 by Bioinformation

Nature文章标题如下

在文章 Fig.5a 

a, UMAP of pan-tumour TME and vascular metacells, coloured by annotated cell identity. The dots represent the metacells produced by SuperCell. Bmem, memory B cells. 


Science | 同款



https://www.science.org/doi/10.1126/science.adf3786

文章中 Fig. 4A

(A) Cortical NSC subtypes and pseudotime. (B) Region and age proportion of the NSCs (left). Markers for the anterior-enriched PMP22+ RG cell subtype (right).

文章源代码公开
https://github.com/sestanlab/Macaque_corticogenesis_scRNA-seq


Rstudio | 画图



01

加载单细胞数据

##系统报错改为英文Sys.setenv(LANGUAGE = "en")##禁止转化为因子options(stringsAsFactors = FALSE)##清空环境rm(list=ls())
#install.packages('Seurat')#library(Seurat)
###加载所需要的包library(Seurat)library(tidyverse)library(dplyr)library(patchwork)##读取10x的数据scRNA.counts=Read10X("E:/super.lesson/s2/GSE197177_RAW/ZY_1/")###创建Seurat对象scRNA = CreateSeuratObject(scRNA.counts , min.cells = 3,project="sampl.1",                            min.features = 40)                       

02

数据预处理

## 数据归一化处理scRNA1 <- NormalizeData(scRNA1, normalization.method = "LogNormalize",                         scale.factor = 10000)## 找高变基因                        scRNA1 <- FindVariableFeatures(scRNA1, selection.method = "vst",                                nfeatures = 2000) ## 数据放缩                               scale.genes <-  rownames(scRNA1)scRNA1 <- ScaleData(scRNA1features = scale.genes)                               

03

降维聚类

##  pca降维scRNA1 <- RunPCA(scRNA1 , features = VariableFeatures(object = scRNA1) )##  聚类scRNA1 <- FindNeighbors(scRNA1, dims = 1:20) scRNA1 <- FindClusters(scRNA1, resolution = 0.5)##  构建进化树scRNA1<-BuildClusterTree(scRNA1)PlotClusterTree(scRNA1)##  unap可视化降维scRNA_harmony=scRNA1scRNA_harmony <- RunUMAP(scRNA_harmony, reduction = "pca",                          dims = 1:10,n.components = 3L)##  注意:reductionumap有三列信息

04

umap维度信息提取

# Extract UMAP information from Seurat Objectumap_1 <- scRNA_harmony[["umap"]]@cell.embeddings[,1]umap_2 <- scRNA_harmony[["umap"]]@cell.embeddings[,2]umap_3 <- scRNA_harmony[["umap"]]@cell.embeddings[,3]
umap=as.data.frame(scRNA_harmony@reductions[["umap"]]@cell.embeddings)
plotting.data=cbind(umap,scRNA_harmony@meta.data)

05

三维可视化

colors<-c('#E41A1C','#377EB8','#4DAF4A','#984EA3','#F29403','#F781BF',"#ed1299")
library(scatterplot3d)# 1. Source the functionsource( "E:/super.lesson/lesson9/huage.3D.plot.R" )# 2. 3D scatter plot
colors.2 <- colors[as.numeric(plotting.data$seurat_clusters)]
s3d <- scatterplot3d(plotting.data[,c(1:3)],angle=40, axis=T,tick.marks=F,col.axis="black", color =colors.2 ,col.grid="#dae1f1", pch = 16, cex.symbols = 0.5,grid=T, box=FALSE )

06

动态三维图

library(plotly)plot_ly(data = plotting.data,         x = ~umap_1, y = ~umap_2, z = ~umap_3,         color = ~seurat_clusters,         colors = colors,        type = "scatter3d",         mode = "markers",         marker = list(size = 1, width=2), # controls size of points        # text=~label, #This is that extra column we made earlier for which we will use for cell ID        hoverinfo="text")
换个角度

强烈推荐,想学生信,复现CNS文章源代码,看👇这个文章

华哥生信团队正式成立!更多新课,更多优惠,更好的授课服务


欢迎关注 | 华哥科研平台



往期精彩内容

CNV变异频率展示 | 单细胞染色体拷贝数变异分析
Science同款 | 密度图--文章源代码复现

亲,写的这么辛苦,记得关注、点赞、打赏哟!