diff --git a/NAMESPACE b/NAMESPACE index 7a44af9..4791d35 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -86,11 +86,13 @@ importFrom(plotthis,LollipopPlot) importFrom(plotthis,Network) importFrom(plotthis,PieChart) importFrom(plotthis,PrepareEnrichrResult) +importFrom(plotthis,RadarPlot) importFrom(plotthis,RarefactionPlot) importFrom(plotthis,RidgePlot) importFrom(plotthis,RingPlot) importFrom(plotthis,SankeyPlot) importFrom(plotthis,ScatterPlot) +importFrom(plotthis,SpiderPlot) importFrom(plotthis,TrendPlot) importFrom(plotthis,UpsetPlot) importFrom(plotthis,VennDiagram) diff --git a/R/cccplot.R b/R/cccplot.R index 18fd8b9..046c519 100644 --- a/R/cccplot.R +++ b/R/cccplot.R @@ -1,9 +1,10 @@ #' Cell-Cell Communication Plot #' #' @description Plot the cell-cell communication. -#' See also the review: https://www.sciencedirect.com/science/article/pii/S2452310021000081 -#' the LIANA package: https://liana-py.readthedocs.io/en/latest/notebooks/basic_usage.html#Tileplot -#' and the CCPlotR package: https://github.com/Sarah145/CCPlotR +#' See also: +#' * The review: \url{https://www.sciencedirect.com/science/article/pii/S2452310021000081} +#' * The LIANA package: \url{https://liana-py.readthedocs.io/en/latest/notebooks/basic_usage.html#Tileplot} +#' * The CCPlotR package: \url{https://github.com/Sarah145/CCPlotR} #' #' @param data A data frame with the cell-cell communication data. #' A typical data frame should have the following columns: @@ -28,6 +29,11 @@ #' * sankey: A sankey plot with the source and target cells as the nodes and the communication as the flows. #' * alluvial: Alias of "sankey". #' * dot: A dot plot with the source and target cells as the nodes and the communication as the dots. +#' @param method The method to determine the plot entities. +#' * aggregation: Aggregate the ligand-receptor pairs interactions for each source-target pair. +#' Only the source / target pairs will be plotted. +#' * interaction: Plot the ligand-receptor pairs interactions directly. +#' The ligand-receptor pairs will also be plotted. #' @param magnitude The column name in the data to use as the magnitude of the communication. #' By default, the second last column will be used. #' See `li.mt.show_methods()` for the available methods in `LIANA`. @@ -71,8 +77,10 @@ #' @examples #' set.seed(8525) #' data(cellphonedb_res) -#' CCCPlot(data = cellphonedb_res) +#' CCCPlot(data = cellphonedb_res, plot_type = "network", legend.position = "none", +#' theme = "theme_blank", theme_args = list(add_coord = FALSE)) #' CCCPlot(cellphonedb_res, plot_type = "chord") +#' CCCPlot(cellphonedb_res, plot_type = "heatmap") #' CCCPlot(cellphonedb_res, plot_type = "dot", weighted = FALSE) #' #' cellphonedb_res_sub <- cellphonedb_res[ @@ -158,7 +166,7 @@ CCCPlot <- function( if (plot_type == "network") { Network(links, from = source_col, to = target_col, node_fill_by = "name", link_curvature = link_curvature, link_weight_name = link_weight_name, link_alpha = link_alpha, - node_fill_name = "Entities", link_weight_by = "interactionStrength", ...) + node_fill_name = "Source/Target", link_weight_by = "interactionStrength", ...) } else if (plot_type %in% c("chord", "circos")) { ChordPlot(links, y = "interactionStrength", from = source_col, to = target_col, ...) @@ -204,7 +212,7 @@ CCCPlot <- function( } else if (plot_type == "heatmap") { data$ligand_receptor <- paste0(data[[ligand_col]], " -> ", data[[receptor_col]]) all_lrs <- unique(data$ligand_receptor) - data <- pivot_wider(data, names_from = ligand_receptor, values_from = magnitude, + data <- pivot_wider(data, names_from = "ligand_receptor", values_from = magnitude, values_fill = 0) Heatmap(data, rows = all_lrs, rows_name = "Ligand -> Receptor", name = magnitude, columns_by = target_col, columns_split_by = source_col, diff --git a/README.md b/README.md index 8f444d3..c885db4 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,12 @@ $ conda install pwwang::r-scplotter ## Credits -`scplotter` is greatly inspired by the [`SCP`][2] package, where the visualization was detached from the analysis and implemented in the [`plotthis`][1] package. The `scplotter` package is built upon the `plotthis` package and provides a set of even higher-level functions to visualize single-cell sequencing data. +`scplotter` draws significant inspiration from the [`SCP`][2] package, which separates visualization from analysis and implements it in the [`plotthis`][1] package. Building on `plotthis`, `scplotter` offers advanced functions for visualizing single-cell sequencing data. Special thanks to the [`scRepertoire`][2] package for its APIs that facilitate the analysis of single-cell TCR/BCR sequencing data. ## Gallery +### scRNA-seq + [`CellDimPlot`][3] ![CellDimPlot](./man/figures/celldimplot.png) @@ -46,6 +48,20 @@ $ conda install pwwang::r-scplotter ![VolcanoPlot](./man/figures/volcanoplot.png) +[`CCCPlot`][10] + +![CCCPlot](./man/figures/cccplot.png) + +### scTCR-seq/scBCR-seq + +[`ClonalVolumePlot`][11] | [`ClonalAbundancePlot`][12] | [`ClonalResidencyPlot`][13] | [`ClonalCompositionPlot`][14] | [`ClonalOverlapPlot`][15] | [`ClonalGeneUsagePlot`][16] + +![clonalstat](./man/figures/clonalstat.png) + +[`ClonalRarefactionPlot`][17] | [`ClonalGeneUsagePlot`][18] | [`ClonalDiversityPlot`][19] | [`ClonalPositionalPlot`][20] + +![clonaldiv](./man/figures/clonaldiv.png) + [1]: https://github.com/pwwang/plotthis [2]: https://zhanghao-njmu.github.io/SCP/index.html [3]: https://pwwang.github.io/scplotter/reference/CellDimPlot.html @@ -55,3 +71,14 @@ $ conda install pwwang::r-scplotter [7]: https://pwwang.github.io/scplotter/reference/EnrichmentPlot.html [8]: https://pwwang.github.io/plotthis/reference/gsea.html [9]: https://pwwang.github.io/plotthis/reference/VolcanoPlot.html +[10]: https://pwwang.github.io/plotthis/reference/CCCPlot.html +[11]: https://pwwang.github.io/scplotter/reference/ClonalVolumePlot.html +[12]: https://pwwang.github.io/scplotter/reference/ClonalAbundancePlot.html +[13]: https://pwwang.github.io/scplotter/reference/ClonalResidencyPlot.html +[14]: https://pwwang.github.io/scplotter/reference/ClonalCompositionPlot.html +[15]: https://pwwang.github.io/scplotter/reference/ClonalOverlapPlot.html +[16]: https://pwwang.github.io/scplotter/reference/ClonalGeneUsagePlot.html +[17]: https://pwwang.github.io/scplotter/reference/ClonalRarefactionPlot.html +[18]: https://pwwang.github.io/scplotter/reference/ClonalGeneUsagePlot.html +[19]: https://pwwang.github.io/scplotter/reference/ClonalDiversityPlot.html +[20]: https://pwwang.github.io/scplotter/reference/ClonalPositionalPlot.html diff --git a/_pkgdown.yml b/_pkgdown.yml index bcad226..8d79ef9 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -11,6 +11,7 @@ reference: - ClustreePlot - EnrichmentPlot - FeatureStatPlot + - CCCPlot - title: scTCR-seq/scBCR-seq desc: Functions for plotting single cell TCR-seq/BCR-seq data contents: @@ -30,6 +31,7 @@ reference: contents: - ifnb_sub - pancreas_sub + - cellphonedb_res - title: Re-exports desc: Functions that are re-exported from plotthis contents: diff --git a/man/CCCPlot.Rd b/man/CCCPlot.Rd index 10cc1f7..deb332f 100644 --- a/man/CCCPlot.Rd +++ b/man/CCCPlot.Rd @@ -52,6 +52,14 @@ Possible values are "network", "chord", "circos", "heatmap", "sankey", "alluvial \item dot: A dot plot with the source and target cells as the nodes and the communication as the dots. }} +\item{method}{The method to determine the plot entities. +\itemize{ +\item aggregation: Aggregate the ligand-receptor pairs interactions for each source-target pair. +Only the source / target pairs will be plotted. +\item interaction: Plot the ligand-receptor pairs interactions directly. +The ligand-receptor pairs will also be plotted. +}} + \item{magnitude}{The column name in the data to use as the magnitude of the communication. By default, the second last column will be used. See \code{li.mt.show_methods()} for the available methods in \code{LIANA}. @@ -103,15 +111,20 @@ A ggplot object or a list if \code{combine} is FALSE } \description{ Plot the cell-cell communication. -See also the review: https://www.sciencedirect.com/science/article/pii/S2452310021000081 -the LIANA package: https://liana-py.readthedocs.io/en/latest/notebooks/basic_usage.html#Tileplot -and the CCPlotR package: https://github.com/Sarah145/CCPlotR +See also: +\itemize{ +\item The review: \url{https://www.sciencedirect.com/science/article/pii/S2452310021000081} +\item The LIANA package: \url{https://liana-py.readthedocs.io/en/latest/notebooks/basic_usage.html#Tileplot} +\item The CCPlotR package: \url{https://github.com/Sarah145/CCPlotR} +} } \examples{ set.seed(8525) data(cellphonedb_res) -CCCPlot(data = cellphonedb_res) +CCCPlot(data = cellphonedb_res, plot_type = "network", legend.position = "none", + theme = "theme_blank", theme_args = list(add_coord = FALSE)) CCCPlot(cellphonedb_res, plot_type = "chord") +CCCPlot(cellphonedb_res, plot_type = "heatmap") CCCPlot(cellphonedb_res, plot_type = "dot", weighted = FALSE) cellphonedb_res_sub <- cellphonedb_res[ diff --git a/man/figures/cccplot.png b/man/figures/cccplot.png new file mode 100644 index 0000000..37b2429 Binary files /dev/null and b/man/figures/cccplot.png differ diff --git a/man/figures/clonaldiv.png b/man/figures/clonaldiv.png new file mode 100644 index 0000000..40de607 Binary files /dev/null and b/man/figures/clonaldiv.png differ diff --git a/man/figures/clonalstat.png b/man/figures/clonalstat.png new file mode 100644 index 0000000..c1f4c7a Binary files /dev/null and b/man/figures/clonalstat.png differ