mirror of
https://github.com/johrpan/geposan.git
synced 2025-10-26 10:47:25 +01:00
plots: Add position plot
This commit is contained in:
parent
19bae34a96
commit
e28bcaafed
3 changed files with 88 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ export(analyze)
|
||||||
export(compare)
|
export(compare)
|
||||||
export(optimal_weights)
|
export(optimal_weights)
|
||||||
export(plot_boxplot)
|
export(plot_boxplot)
|
||||||
|
export(plot_positions)
|
||||||
export(plot_scores)
|
export(plot_scores)
|
||||||
export(preset)
|
export(preset)
|
||||||
export(ranking)
|
export(ranking)
|
||||||
|
|
|
||||||
65
R/plots.R
65
R/plots.R
|
|
@ -1,3 +1,68 @@
|
||||||
|
#' Plot gene positions.
|
||||||
|
#'
|
||||||
|
#' This function requires the package `plotly`.
|
||||||
|
#'
|
||||||
|
#' @param species_ids IDs of species to show in the plot.
|
||||||
|
#' @param gene_sets A list of gene sets (containing vectors of gene IDs) that
|
||||||
|
#' 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 use_positions Whether to display positions instead of distances.
|
||||||
|
#'
|
||||||
|
#' @export
|
||||||
|
plot_positions <- function(species_ids,
|
||||||
|
gene_sets,
|
||||||
|
labels,
|
||||||
|
use_positions = FALSE) {
|
||||||
|
if (!requireNamespace("plotly", quietly = TRUE)) {
|
||||||
|
stop("Please install \"plotly\" to use this function.")
|
||||||
|
}
|
||||||
|
|
||||||
|
data <- merge(
|
||||||
|
geposan::distances[gene %chin% unlist(gene_sets) &
|
||||||
|
species %chin% species_ids],
|
||||||
|
geposan::genes[, .(id, name)],
|
||||||
|
by.x = "gene", by.y = "id"
|
||||||
|
)
|
||||||
|
|
||||||
|
if (use_positions) {
|
||||||
|
data[, value := position]
|
||||||
|
} else {
|
||||||
|
data[, value := distance]
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add labels for each gene set.
|
||||||
|
for (i in seq_along(gene_sets)) {
|
||||||
|
data[gene %chin% gene_sets[[i]], label := labels[i]]
|
||||||
|
}
|
||||||
|
|
||||||
|
species <- geposan::species[id %chin% species_ids]
|
||||||
|
|
||||||
|
yaxis_title <- if (use_positions) {
|
||||||
|
"Position [Bp]"
|
||||||
|
} else {
|
||||||
|
"Distance to telomeres [Bp]"
|
||||||
|
}
|
||||||
|
|
||||||
|
plotly::plot_ly(
|
||||||
|
data = data,
|
||||||
|
x = ~species,
|
||||||
|
y = ~value,
|
||||||
|
color = ~label,
|
||||||
|
text = ~name,
|
||||||
|
type = "scatter",
|
||||||
|
mode = "markers"
|
||||||
|
) |> plotly::layout(
|
||||||
|
xaxis = list(
|
||||||
|
title = "Species",
|
||||||
|
tickvals = species$id,
|
||||||
|
ticktext = species$name
|
||||||
|
),
|
||||||
|
yaxis = list(title = yaxis_title)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#' Plot a ranking as a scatter plot of scores.
|
#' Plot a ranking as a scatter plot of scores.
|
||||||
#'
|
#'
|
||||||
#' This function requires the package `plotly`.
|
#' This function requires the package `plotly`.
|
||||||
|
|
|
||||||
22
man/plot_positions.Rd
Normal file
22
man/plot_positions.Rd
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/plots.R
|
||||||
|
\name{plot_positions}
|
||||||
|
\alias{plot_positions}
|
||||||
|
\title{Plot gene positions.}
|
||||||
|
\usage{
|
||||||
|
plot_positions(species_ids, gene_sets, labels, use_positions = FALSE)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{species_ids}{IDs of species to show in the plot.}
|
||||||
|
|
||||||
|
\item{gene_sets}{A list of gene sets (containing vectors of gene IDs) that
|
||||||
|
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{use_positions}{Whether to display positions instead of distances.}
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
This function requires the package \code{plotly}.
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue