mirror of
https://github.com/johrpan/geposan.git
synced 2025-10-25 19:37:23 +02:00
Implement gene set highlighting in positions plot
This commit is contained in:
parent
7e53015168
commit
e41d02c659
2 changed files with 26 additions and 2 deletions
23
R/plots.R
23
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(
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue