1引言
有粉丝想画 scanpy 的 tracksPlot,但是单细胞上游全是用的seurat 软件,只想提取数据画类似的图。粉丝网上找了一个教程,但是画不出来,于是我直接在 scRNAtoolVis 里加个函数即可,虽说不能画的一模一样,大概是那个感觉就行了。
scanpy 的 tracksPlot 图:
热图:
2安装
重新安装获取新功能:
install.packages('devtools')
devtools::install_github('junjunlab/scRNAtoolVis')
library(scRNAtoolVis)
3使用
加载内置测试数据:
library(scRNAtoolVis)
# load test data
httest <- system.file("extdata", "htdata.RDS", package = "scRNAtoolVis")
pbmc <- readRDS(httest)
# load markergene
markergene <- system.file("extdata", "top5pbmc.markers.csv", package = "scRNAtoolVis")
markers <- read.table(markergene, sep = ',', header = TRUE) |>
dplyr::group_by(cluster) |>
slice_head(n = 3)
head(markers,3)
# # A tibble: 3 × 7
# # Groups: cluster [1]
# p_val avg_log2FC pct.1 pct.2 p_val_adj cluster gene
# <dbl> <dbl> <dbl> <dbl> <dbl> <int> <chr>
# 1 1.74e-109 1.07 0.897 0.593 2.39e-105 0 LDHB
# 2 1.17e- 83 1.33 0.435 0.108 1.60e- 79 0 CCR7
# 3 3.28e- 49 1.05 0.333 0.103 4.50e- 45 0 LEF1
画五个基因:
# plot
tracksPlot(object = pbmc,
genes = unique(markers$gene)[1:5])
或者直接输入 findAllMarkers 函数的输出数据框类型:
# use findAllMarkers output
tracksPlot(object = pbmc,
genes = markers |> head(9))
给分面设置颜色:
# change strip color
tracksPlot(object = pbmc,
genes = markers |> head(9),
strip_nested_params = list(background_x = ggh4x::elem_list_rect(fill = rainbow(9))))
设置分面间距:
# panel space
tracksPlot(object = pbmc,
genes = markers |> head(9),
strip_nested_params = list(background_x = ggh4x::elem_list_rect(fill = rainbow(9))),
theme_params = list(panel.spacing.x = unit(0,"mm")))
设置分面大小:
# panel size
tracksPlot(object = pbmc,
genes = markers |> head(9),
strip_nested_params = list(background_x = ggh4x::elem_list_rect(fill = rainbow(9))),
theme_params = list(panel.spacing.x = unit(0,"mm")),
facet_nested_params = list(space = "free"))
修改颜色:
# tracksplot color
tracksPlot(object = pbmc,
genes = markers |> head(9),
strip_nested_params = list(background_x = ggh4x::elem_list_rect(fill = rainbow(9))),
theme_params = list(panel.spacing.x = unit(0,"mm")),
facet_nested_params = list(space = "free")) +
scale_fill_brewer(palette = "Set1")
热图:
# heatmap
tracksPlot(object = pbmc,
genes = markers |> head(9),
plot.type = "heatmap")
修改颜色:
# color
tracksPlot(object = pbmc,
genes = markers |> head(9),
plot.type = "heatmap") +
scale_fill_gradient2(low = "blue",mid = "white",high = "red",na.value = "white")
4结尾
路漫漫其修远兮,吾将上下而求索。
欢迎加入生信交流群。加我微信我也拉你进 微信群聊 老俊俊生信交流群 (微信交流群需收取 20 元入群费用,一旦交费,拒不退还!(防止骗子和便于管理)) 。QQ 群可免费加入, 记得进群按格式修改备注哦。
声明:文中观点不代表本站立场。本文传送门:https://eyangzhen.com/221735.html