美文网首页
ktplots(一):绘制个性化气泡图

ktplots(一):绘制个性化气泡图

作者: 生信宝库 | 来源:发表于2023-06-17 15:05 被阅读0次

前言

Immugent最近淘到了一款非常好用的画图R包:ktplots,于是就迫不及待地的想把它分享给大家。总体来说,这个包非常的轻便,而且可以对我们常用的图进行美化和针对性修改,非常方便。

鉴于ktplots包功能较多,Immugent打算连续推出3篇推文来对它不同的绘图功能进行介绍。本期推文主要关注于如何对气泡图进行美化,以及如何对我们关注的功能通路或者信号进行突出显示。


代码流程

安装ktplots包

if (!requireNamespace("devtools", quietly = TRUE))
    install.packages("devtools")
if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
devtools::install_github('zktuong/ktplots', dependencies = TRUE)

为了方便大家复现,直接使用包自带的模拟数据

library(ktplots)
library(SingleCellExperiment)
data(kidneyimmune)
#Some functions accept Seurat objects too.

# pvals <- read.delim("pvalues.txt", check.names = FALSE)
# means <- read.delim("means.txt", check.names = FALSE)

# I've provided an example dataset
data(cpdb_output)
plot_cpdb(cell_type1 = 'B cell', cell_type2 = 'CD4T cell', scdata = kidneyimmune,
 idents = 'celltype', # column name where the cell ids are located in the metadata
 split.by = 'Experiment', # column name where the grouping column is. Optional.
 means = means, pvals = pvals,
 genes = c("XCR1", "CXCL10", "CCL5")) +
small_axis(fontsize = 3) + small_grid() + small_guide() + small_legend(fontsize = 2) # some helper functions included in ktplots to help with the plotting
image.png

You can also try specifying gene.family option which will grep some pre-determined genes.

plot_cpdb(cell_type1 = 'B cell', cell_type2 = 'CD4T cell', scdata = kidneyimmune,
    idents = 'celltype', means = means, pvals = pvals, split.by = 'Experiment',
    gene.family = 'chemokines') + small_guide() + small_axis() + small_legend(keysize=.5)
image.png
plot_cpdb(cell_type1 = 'B cell', cell_type2 = 'CD4T cell', scdata = kidneyimmune,
    idents = 'celltype', means = means, pvals = pvals, split.by = 'Experiment',
    gene.family = 'chemokines', col_option = "maroon", highlight = "blue") + small_guide() + small_axis() + small_legend(keysize=.5)
image.png
plot_cpdb(cell_type1 = 'B cell', cell_type2 = 'CD4T cell', scdata = kidneyimmune,
    idents = 'celltype', means = means, pvals = pvals, split.by = 'Experiment',
    gene.family = 'chemokines', col_option = viridis::cividis(50)) + small_guide() + small_axis() + small_legend(keysize=.5)
image.png

A new style to plot inspired from squidpy.pl.ligrec where significant interactions are shown as outline instead.

plot_cpdb(cell_type1 = 'B cell', cell_type2 = 'CD4T cell', scdata = kidneyimmune,
    idents = 'celltype', means = means, pvals = pvals, split.by = 'Experiment',
    gene.family = 'chemokines', noir = TRUE) + small_guide() + small_axis() + small_legend(keysize=.5)
image.png
plot_cpdb(cell_type1 = 'B cell', cell_type2 = 'CD4T cell', scdata = kidneyimmune,
    idents = 'celltype', means = means, pvals = pvals, split.by = 'Experiment',
    gene.family = 'chemokines', default_style = FALSE) + small_guide() + small_axis() + small_legend(keysize=.5)
image.png

You can now also specify more than 1 gene families:

p <- plot_cpdb("B cell", "CD4T cell", kidneyimmune, "celltype", means, pvals,
        split.by = "Experiment", gene.family = c("Coinhibitory", "Costimulatory"),
        cluster_rows = FALSE, # ensures that the families are separate
        keep_significant_only = TRUE)
image.png

说在最后

在没有ktplots包之前,大家如果想突出某一些感兴趣的信号通路,只能通过AI手动添加。而ktplots包就是为了彻底实现随心所欲的修改绘制的气泡图,而且可以根据不同的信号之间的规律进行自动识别。当然,ktplots包还有很多其它参数,Immugent在这里只是对其常用的几个参数进行讲解,感兴趣的小伙伴可以在自己的电脑上安装这个包来研究它每一个参数的意义。

好啦,本期分享到这里就结束了,我们下期再会~~

相关文章

网友评论

      本文标题:ktplots(一):绘制个性化气泡图

      本文链接:https://www.haomeiwen.com/subject/sugdydtx.html