mirror of
https://github.com/johrpan/geposan.git
synced 2025-10-26 10:47:25 +01:00
plots: Add chromosome plot
This commit is contained in:
parent
1058dfaa17
commit
2f3dc80a2f
2 changed files with 52 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_chromosomes)
|
||||||
export(plot_positions)
|
export(plot_positions)
|
||||||
export(plot_scores)
|
export(plot_scores)
|
||||||
export(preset)
|
export(preset)
|
||||||
|
|
|
||||||
51
R/plots.R
51
R/plots.R
|
|
@ -188,3 +188,54 @@ plot_boxplot <- function(ranking, gene_sets = NULL, labels = NULL) {
|
||||||
type = "box"
|
type = "box"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#' Show the distribution of scores across chromosomes.
|
||||||
|
#'
|
||||||
|
#' This function requires the package `plotly`.
|
||||||
|
#'
|
||||||
|
#' @param ranking The ranking to visualize.
|
||||||
|
#'
|
||||||
|
#' @seealso ranking()
|
||||||
|
#'
|
||||||
|
#' @export
|
||||||
|
plot_chromosomes <- function(ranking) {
|
||||||
|
if (!requireNamespace("plotly", quietly = TRUE)) {
|
||||||
|
stop("Please install \"plotly\" to use this function.")
|
||||||
|
}
|
||||||
|
|
||||||
|
data <- merge(ranking, geposan::genes, by.x = "gene", by.y = "id")
|
||||||
|
data <- data[, .(score = mean(score)), by = "chromosome"]
|
||||||
|
|
||||||
|
# Get an orderable integer from a chromosome name.
|
||||||
|
chromosome_index <- function(chromosome) {
|
||||||
|
index <- suppressWarnings(as.integer(chromosome))
|
||||||
|
|
||||||
|
ifelse(
|
||||||
|
!is.na(index),
|
||||||
|
index,
|
||||||
|
ifelse(
|
||||||
|
chromosome == "X",
|
||||||
|
998,
|
||||||
|
999
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
data[, index := chromosome_index(chromosome)]
|
||||||
|
setorder(data, "index")
|
||||||
|
|
||||||
|
plotly::plot_ly(
|
||||||
|
data = data,
|
||||||
|
x = ~chromosome,
|
||||||
|
y = ~score,
|
||||||
|
type = "bar"
|
||||||
|
) |>
|
||||||
|
plotly::layout(
|
||||||
|
xaxis = list(
|
||||||
|
title = "Chromosome",
|
||||||
|
categoryorder = "array",
|
||||||
|
categoryarray = ~chromosome
|
||||||
|
),
|
||||||
|
yaxis = list(title = "Mean score")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue