jamesbang

V1

2022/10/06阅读：30主题：雁栖湖

# 🤩 scRNA-seq | 吐血整理的单细胞入门教程（基础可视化）（五）

## 2用到的包

``rm(list = ls())library(tidyverse)library(scater)library(SingleCellExperiment)library(ggsci)library(scater)``

## 3示例数据

### 3.1 读入数据

``counts <- read.table("./molecules.txt", sep = "\t")annotation <- read.table("./annotation.txt", sep = "\t", header = TRUE)``

### 3.2 创建SingleCellExperiment对象

``# 注意assays必须是matrixtung <- SingleCellExperiment(  assays = list(counts = as.matrix(counts)),  colData = annotation)assay(tung, "logcounts") <- log2(counts(tung) + 1)colData(tung)\$total_counts <- colSums(counts(tung))tung``

## 4细胞信息可视化

### 4.1 提取信息

``cell_info <- as.data.frame(colData(tung))head(cell_info)``

### 4.2 可视化

``cell_info %>%   ggplot(aes(x = batch, y = total_counts)) +  geom_violin(aes(fill= batch)) +   theme_bw() +   theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))+  scale_fill_npg()``

## 5特定gene及batch的可视化

### 5.1 补充一下

``tung %>%   ggcells(aes(x = batch, y = total_counts)) +   geom_violin(aes(fill = batch)) +   theme_bw() +   theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))+  scale_fill_lancet()``

### 5.2 特定基因可视化

``tung %>%   ggcells(aes(x = batch, y = ENSG00000198938), exprs_values = "logcounts") +   geom_violin(aes(fill = batch)) +  theme_bw() +   theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))+  scale_fill_aaas()``

##### jamesbang
V1

wx🔍: Grassssss 卷起来了