From 7e53015168889baf86945d880f96f826f6bdd0a0 Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Tue, 17 May 2022 21:48:30 +0200 Subject: [PATCH] Add chromosomal positions plot --- NAMESPACE | 1 + R/plots.R | 41 +++++++++++++++++++++++++++++++++- man/plot_scores_by_position.Rd | 22 ++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 man/plot_scores_by_position.Rd diff --git a/NAMESPACE b/NAMESPACE index 841e328..3f1aefe 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -21,6 +21,7 @@ export(plot_chromosomes) export(plot_positions) export(plot_rankings) export(plot_scores) +export(plot_scores_by_position) export(preset) export(proximity) export(ranking) diff --git a/R/plots.R b/R/plots.R index 6c41cf7..98b9b50 100644 --- a/R/plots.R +++ b/R/plots.R @@ -46,7 +46,8 @@ plot_positions <- function(species_ids, gene_sets) { ), yaxis = list(title = "Distance to telomeres [Bp]"), bargap = 0.9 - ) |> plotly::add_bars( + ) |> + plotly::add_bars( data = species_max_distance, x = ~species, y = ~max_distance, @@ -379,3 +380,41 @@ plot_chromosomes <- function(ranking) { yaxis = list(title = "Mean score") ) } + +#' Plot scores in relation to chromosomal position of genes. +#' +#' @param ranking The ranking to visualize. +#' @param chromosome_name The chromosome to visualize. +#' +#' @return A `plotly` figure. +#' @seealso ranking() +#' +#' @export +plot_scores_by_position <- function(ranking, chromosome_name) { + if (!requireNamespace("plotly", quietly = TRUE)) { + stop("Please install \"plotly\" to use this function.") + } + + chromosome_name_ <- chromosome_name + + data <- merge( + ranking, + geposan::distances[ + species == "hsapiens" & + chromosome_name == chromosome_name_ + ], + by = "gene" + ) + + plotly::plot_ly() |> + plotly::add_markers( + data = data, + x = ~start_position, + y = ~score, + hoverinfo = "skip" + ) |> + plotly::layout( + xaxis = list(title = "Position (Bp)"), + yaxis = list(title = "Score") + ) +} diff --git a/man/plot_scores_by_position.Rd b/man/plot_scores_by_position.Rd new file mode 100644 index 0000000..1124359 --- /dev/null +++ b/man/plot_scores_by_position.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plots.R +\name{plot_scores_by_position} +\alias{plot_scores_by_position} +\title{Plot scores in relation to chromosomal position of genes.} +\usage{ +plot_scores_by_position(ranking, chromosome_name) +} +\arguments{ +\item{ranking}{The ranking to visualize.} + +\item{chromosome_name}{The chromosome to visualize.} +} +\value{ +A \code{plotly} figure. +} +\description{ +Plot scores in relation to chromosomal position of genes. +} +\seealso{ +ranking() +}