plots: Add rankings plot

This commit is contained in:
Elias Projahn 2021-12-02 15:28:03 +01:00
parent 2c15ba55c1
commit f997b5fdd7
4 changed files with 100 additions and 7 deletions

View file

@ -8,6 +8,7 @@ export(optimal_weights)
export(plot_boxplot)
export(plot_chromosomes)
export(plot_positions)
export(plot_rankings)
export(plot_scores)
export(preset)
export(ranking)

View file

@ -63,6 +63,79 @@ plot_positions <- function(species_ids,
}
#' Plot a side-by-side comparison of multiple rankings.
#'
#' Each ranking's scores will be shown as a vertical violin plot without any
#' additional markings. The gene sets will be shown as markers on top of the
#' density visualization.
#'
#' This function requires the package `plotly`.
#'
#' @param rankings A named list of rankings to display. The names will be shown
#' as labels in the plot.
#' @param gene_sets A named list of vectors of gene IDs to highlight. The names
#' will be used to distinguish the sets and in the legend.
#'
#' @export
plot_rankings <- function(rankings, gene_sets) {
if (!requireNamespace("plotly", quietly = TRUE)) {
stop("Please install \"plotly\" to use this function.")
}
plot <- plotly::plot_ly(colors = "Set2") |>
plotly::layout(
xaxis = list(
title = "Ranking",
tickvals = names(rankings)
),
yaxis = list(title = "Score")
)
is_first <- TRUE
for (ranking_name in names(rankings)) {
ranking <- rankings[[ranking_name]]
data <- merge(
ranking,
geposan::genes,
by.x = "gene",
by.y = "id"
)
plot <- plot |> plotly::add_trace(
data = ranking,
x = ranking_name,
y = ~score,
color = "All genes",
type = "violin",
spanmode = "hard",
points = FALSE,
showlegend = is_first,
hoverinfo = "skip"
)
for (gene_set_name in names(gene_sets)) {
gene_set <- gene_sets[[gene_set_name]]
plot <- plot |> plotly::add_markers(
data = data[gene %chin% gene_set],
x = ranking_name,
y = ~score,
text = ~name,
color = gene_set_name,
showlegend = is_first,
marker = list(size = 20, opacity = 0.66)
)
}
is_first <- FALSE
}
plot
}
#' Plot a ranking as a scatter plot of scores.
#'
#' This function requires the package `plotly`.

23
man/plot_rankings.Rd Normal file
View file

@ -0,0 +1,23 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plots.R
\name{plot_rankings}
\alias{plot_rankings}
\title{Plot a side-by-side comparison of multiple rankings.}
\usage{
plot_rankings(rankings, gene_sets)
}
\arguments{
\item{rankings}{A named list of rankings to display. The names will be shown
as labels in the plot.}
\item{gene_sets}{A named list of vectors of gene IDs to highlight. The names
will be used to distinguish the sets and in the legend.}
}
\description{
Each ranking's scores will be shown as a vertical violin plot without any
additional markings. The gene sets will be shown as markers on top of the
density visualization.
}
\details{
This function requires the package \code{plotly}.
}

View file

@ -5,7 +5,7 @@
\title{Create a new preset.}
\usage{
preset(
methods = c("clusteriness", "correlation", "neural", "proximity"),
methods = c("clusteriness", "correlation", "neural", "adjacency", "proximity"),
species_ids = NULL,
gene_ids = NULL,
reference_gene_ids = NULL,
@ -40,14 +40,10 @@ Available methods are:
\itemize{
\item \code{clusteriness} How much the gene distances to the nearest telomere
cluster across species.
\item \code{clusteriness_positions} The same as \code{clusteriness} but using absolute
gene positions instead of distances.
\item \code{correlation} The mean correlation of gene distances to the nearest
telomere across species.
\item \code{correlation_positions} Correlation using position data.
\item \code{neural} Assessment by neural network trained using distances.
\item \code{neural_positions} Assessment by neural network trained using absolute
position data.
\item \code{neural} Assessment by neural network trained on the reference genes.
\item \code{adjacency} Proximity to reference genes.
\item \code{proximity} Mean proximity to telomeres.
}