This guide provides an overview of the CCPlotR package, a small R package for visualising results from tools that predict cell-cell interactions from scRNA-seq data.
Predicting cell-cell interactions from scRNA-seq data is now a common component of a single-cell analysis workflow (Armingol et al. (2021), Almet et al. (2021)). There have been many tools published in recent years specifically for this purpose (Dimitrov et al. (2022), Efremova et al. (2020), Hou et al. (2020), Jin et al. (2021)). These tools typically return a table of predicted interactions that depicts the sending and receiving cell type, the ligand and receptor genes and some sort of score for ranking the interactions. These tables can be quite large and depending on the amount of cell types included in the analysis, this data can get pretty complex and challenging to visualise. Many tools for predicting cell-cell interactions have built-in visualisation methods but some don’t and it can be time consuming and impractical to install some of these methods just for the purpose of visualising the results if you’re using a different tool to predict the interactions. For these reasons, we have developed a lightweight R package that allows the user to easily generate visualisations of cell-cell interactions with minimal code, regardless of which tool was used for predicting the interactions.
CCPlotR makes generic plots that can be used to visualise results
from multiple tools such as Liana, CellPhoneDB, NATMI etc. All it
requires as input is a dataframe with columns source
,
target
, ligand
, receptor
and
score
. It should look something like this:
source | target | ligand | receptor | score |
---|---|---|---|---|
B | CD8 T | HLA-DQA1 | LAG3 | 7.22 |
B | CD8 T | HLA-DRA | LAG3 | 5.59 |
CD8 T | NK | B2M | KIR2DL3 | 5.52 |
B | CD8 T | HLA-DQA2 | LAG3 | 5.41 |
NK | B | LGALS1 | CD69 | 4.15 |
B | CD8 T | ICAM3 | ITGAL | 2.34 |
For some of the plots, there is an option to also show the expression of the ligands and receptors in each cell type. For those plots, a second dataframe is required, which holds the mean expression values for each gene in each cell type and should look something like this:
cell_type | gene | mean_exp |
---|---|---|
B | ACTR2 | 0.363 |
B | ADA | 0.0170 |
B | ADAM10 | 0.0833 |
B | ADAM28 | 0.487 |
B | ADCY7 | 0.0336 |
B | ADRB2 | 0.0178 |
The package comes with toy datasets (toy_data
,
toy_exp
) which you can see for examples of input data.
library(CCPlotR)
data(toy_data, toy_exp, package = 'CCPlotR')
head(toy_data)
#> # A tibble: 6 × 5
#> source target ligand receptor score
#> <chr> <chr> <chr> <chr> <dbl>
#> 1 B CD8 T HLA-DQA1 LAG3 7.22
#> 2 B CD8 T HLA-DRA LAG3 5.59
#> 3 B CD8 T HLA-DQB1 LAG3 5.59
#> 4 B CD8 T HLA-DQA2 LAG3 5.41
#> 5 B CD8 T HLA-DRB5 LAG3 5.26
#> 6 B CD8 T HLA-DRB1 LAG3 5.12
head(toy_exp)
#> # A tibble: 6 × 3
#> # Groups: cell_type [1]
#> cell_type gene mean_exp
#> <chr> <chr> <dbl>
#> 1 B ACTR2 0.363
#> 2 B ADA 0.0170
#> 3 B ADAM10 0.0833
#> 4 B ADAM28 0.487
#> 5 B ADCY7 0.0336
#> 6 B ADRB2 0.0178
The package contains functions for making six types of plots:
cc_heatmap
, cc_dotplot
,
cc_network
, cc_circos
, cc_arrow
and cc_sigmoid
. Below are some examples of each plot
type.
The cc_heatmap
function can generate heatmaps in four
different styles. Option A just displays the total number of
interactions between each pair of cell types and option B shows the
ligands, receptors and cell types involved in each interaction as well
as their score. For option B, only a small portion of top interactions
are shown to avoid cluttering the plot. There is also an option to
generate heatmaps in the style of popular cell-cell interaction
prediction tools such as CellPhoneDB and Liana.
The cc_dotplot
function can generate dotplots in four
different styles. Option A just displays the total number of
interactions between each pair of cell types and option B shows the
ligands, receptors and cell types involved in each interaction as well
as their score. For option B, only a small portion of top interactions
are shown to avoid cluttering the plot. There is also an option to
generate dotplots in the style of popular cell-cell interaction
prediction tools such as CellPhoneDB and Liana.
The cc_network
function can generate two different types
of network plots. In option A, the nodes are cell types and the weight
of the edges corresponds to the total number of interactions between a
given pair of cell types. In option B, the nodes are ligand and receptor
genes, coloured by which cell type is expressing them. For option B,
only a small portion of top interactions are shown to avoid cluttering
the plot.
The cc_circos
function can generate three different
types of circos plots. Option A generates a circos plot where the width
of the links represents the total number of interactions between each
pair of cell types. Option B generates a circos plot showing the
ligands, receptors and cell types involved in the top portion of
interactions. Option C expands on option B by also showing the mean
expression of the ligand and receptor genes in each cell type. In
options B and C, the weight of the links represents the score of the
interaction.
The cc_arrow
function generates plots showing the
interactions between a given pair of cell types. Option A just shows
which ligands/receptors are interacting between a pair of cell types and
option B also shows the expression of the ligand/receptor genes in each
cell type. In both options, the weight of the arrow represents the score
of the interaction.
By default, CCPlotR uses a colour palette that contains 15 colourblind-friendly colours.
Because all plotting functions (with the exception of
cc_circos
) are built on top of ggplot2, it’s easy to
customise and modify the plots according to the users preferences.
Colours, fonts and themes can easily be updated using the usual ggplot2
syntax.
library(ggplot2)
library(patchwork)
p1 <- cc_network(toy_data, option = "B") + labs(title = "Default")
p2 <- cc_network(toy_data, option = "B") + scale_fill_manual(values = rainbow(3)) + labs(title = "Update colours")
#> Scale for fill is already present.
#> Adding another scale for fill, which will replace the existing scale.
p3 <- cc_network(toy_data, option = "B") + theme_grey() + labs(title = "Update theme")
p4 <- cc_network(toy_data, option = "B") + theme(legend.position = "top") + labs(title = "Update legend position")
p1 + p2 + p3 + p4
The cc_circos
function uses the circlize package to
generate to the plots so more information about them can be found here.
sessionInfo()
#> R version 4.4.1 (2024-06-14)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 24.04.1 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=C
#> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
#> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
#>
#> time zone: Etc/UTC
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] patchwork_1.3.0 ggplot2_3.5.1 CCPlotR_1.5.0 BiocStyle_2.33.1
#>
#> loaded via a namespace (and not attached):
#> [1] tidyselect_1.2.1 viridisLite_0.4.2 dplyr_1.1.4
#> [4] farver_2.1.2 viridis_0.6.5 ggraph_2.2.1
#> [7] fastmap_1.2.0 tweenr_2.0.3 digest_0.6.37
#> [10] lifecycle_1.0.4 cluster_2.1.6 magrittr_2.0.3
#> [13] compiler_4.4.1 rlang_1.1.4 sass_0.4.9
#> [16] tools_4.4.1 igraph_2.1.1 utf8_1.2.4
#> [19] yaml_2.3.10 knitr_1.48 labeling_0.4.3
#> [22] graphlayouts_1.2.0 plyr_1.8.9 xml2_1.3.6
#> [25] RColorBrewer_1.1-3 withr_3.0.2 purrr_1.0.2
#> [28] BiocGenerics_0.51.3 sys_3.4.3 grid_4.4.1
#> [31] polyclip_1.10-7 ggh4x_0.2.8 stats4_4.4.1
#> [34] fansi_1.0.6 colorspace_2.1-1 scales_1.3.0
#> [37] iterators_1.0.14 MASS_7.3-61 cli_3.6.3
#> [40] rmarkdown_2.28 crayon_1.5.3 generics_0.1.3
#> [43] rjson_0.2.23 commonmark_1.9.2 cachem_1.1.0
#> [46] ggforce_0.4.2 stringr_1.5.1 parallel_4.4.1
#> [49] BiocManager_1.30.25 matrixStats_1.4.1 vctrs_0.6.5
#> [52] yulab.utils_0.1.7 jsonlite_1.8.9 IRanges_2.39.2
#> [55] GetoptLong_1.0.5 S4Vectors_0.43.2 ggrepel_0.9.6
#> [58] clue_0.3-65 maketools_1.3.1 foreach_1.5.2
#> [61] tidyr_1.3.1 jquerylib_0.1.4 glue_1.8.0
#> [64] codetools_0.2-20 ggtext_0.1.2 stringi_1.8.4
#> [67] shape_1.4.6.1 gtable_0.3.6 ComplexHeatmap_2.21.1
#> [70] munsell_0.5.1 tibble_3.2.1 pillar_1.9.0
#> [73] htmltools_0.5.8.1 circlize_0.4.16 R6_2.5.1
#> [76] doParallel_1.0.17 tidygraph_1.3.1 evaluate_1.0.1
#> [79] highr_0.11 markdown_1.13 png_0.1-8
#> [82] gridtext_0.1.5 ggbump_0.1.0 memoise_2.0.1
#> [85] ggfun_0.1.7 bslib_0.8.0 Rcpp_1.0.13
#> [88] gridExtra_2.3 scatterpie_0.2.4 xfun_0.48
#> [91] fs_1.6.4 forcats_1.0.0 buildtools_1.0.0
#> [94] pkgconfig_2.0.3 GlobalOptions_0.1.2