diff --git a/R/plots.R b/R/plots.R index 98b9b50..f71d715 100644 --- a/R/plots.R +++ b/R/plots.R @@ -385,12 +385,16 @@ plot_chromosomes <- function(ranking) { #' #' @param ranking The ranking to visualize. #' @param chromosome_name The chromosome to visualize. +#' @param gene_sets Named list of vectors of genes to highlight. The list names +#' will be used as labels. #' #' @return A `plotly` figure. #' @seealso ranking() #' #' @export -plot_scores_by_position <- function(ranking, chromosome_name) { +plot_scores_by_position <- function(ranking, + chromosome_name, + gene_sets = NULL) { if (!requireNamespace("plotly", quietly = TRUE)) { stop("Please install \"plotly\" to use this function.") } @@ -406,11 +410,28 @@ plot_scores_by_position <- function(ranking, chromosome_name) { by = "gene" ) + data[, `:=`(gene_set = "All genes", color = base_color())] + + index <- 1 + for (gene_set_name in names(gene_sets)) { + gene_set_genes <- gene_sets[[gene_set_name]] + data[ + gene %chin% gene_set_genes, + `:=`( + gene_set = gene_set_name, + color = gene_set_color(index) + ) + ] + + index <- index + 1 + } + plotly::plot_ly() |> plotly::add_markers( data = data, x = ~start_position, y = ~score, + name = ~gene_set, hoverinfo = "skip" ) |> plotly::layout( diff --git a/man/plot_scores_by_position.Rd b/man/plot_scores_by_position.Rd index 1124359..0f01862 100644 --- a/man/plot_scores_by_position.Rd +++ b/man/plot_scores_by_position.Rd @@ -4,12 +4,15 @@ \alias{plot_scores_by_position} \title{Plot scores in relation to chromosomal position of genes.} \usage{ -plot_scores_by_position(ranking, chromosome_name) +plot_scores_by_position(ranking, chromosome_name, gene_sets = NULL) } \arguments{ \item{ranking}{The ranking to visualize.} \item{chromosome_name}{The chromosome to visualize.} + +\item{gene_sets}{Named list of vectors of genes to highlight. The list names +will be used as labels.} } \value{ A \code{plotly} figure.