From 19bae34a96b48bb699ce1bc4afda9d8fe2543496 Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Mon, 15 Nov 2021 09:21:37 +0100 Subject: [PATCH] plots: Add max_rank to score plot --- R/plots.R | 27 ++++++++++++++++++++++++++- man/plot_scores.Rd | 5 ++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/R/plots.R b/R/plots.R index 6eabcdc..9b2ee0d 100644 --- a/R/plots.R +++ b/R/plots.R @@ -7,11 +7,16 @@ #' will be highlighted in the plot. #' @param labels Labels for the gene sets. This is required if gene sets are #' given and has to have the same length. +#' @param max_rank The maximum rank of the highlighted genes. All genes that +#' are ranked lower will appear greyed out. #' #' @seealso ranking() #' #' @export -plot_scores <- function(ranking, gene_sets = NULL, labels = NULL) { +plot_scores <- function(ranking, + gene_sets = NULL, + labels = NULL, + max_rank = NULL) { if (!requireNamespace("plotly", quietly = TRUE)) { stop("Please install \"plotly\" to use this function.") } @@ -60,6 +65,26 @@ plot_scores <- function(ranking, gene_sets = NULL, labels = NULL) { ) } + + if (!is.null(max_rank)) { + first_not_included_rank <- max_rank + 1 + last_rank <- ranking[, .N] + + if (first_not_included_rank <= last_rank) { + plot <- plot |> plotly::layout( + shapes = list( + type = "rect", + fillcolor = "black", + opacity = 0.1, + x0 = first_not_included_rank, + x1 = last_rank, + y0 = 0.0, + y1 = 1.0 + ) + ) + } + } + plot } diff --git a/man/plot_scores.Rd b/man/plot_scores.Rd index a09c590..78d01e8 100644 --- a/man/plot_scores.Rd +++ b/man/plot_scores.Rd @@ -4,7 +4,7 @@ \alias{plot_scores} \title{Plot a ranking as a scatter plot of scores.} \usage{ -plot_scores(ranking, gene_sets = NULL, labels = NULL) +plot_scores(ranking, gene_sets = NULL, labels = NULL, max_rank = NULL) } \arguments{ \item{ranking}{The ranking to visualize.} @@ -14,6 +14,9 @@ will be highlighted in the plot.} \item{labels}{Labels for the gene sets. This is required if gene sets are given and has to have the same length.} + +\item{max_rank}{The maximum rank of the highlighted genes. All genes that +are ranked lower will appear greyed out.} } \description{ This function requires the package \code{plotly}.