mirror of
https://github.com/johrpan/geposan.git
synced 2025-10-26 18:57:25 +01:00
plots: Unify colors
This commit is contained in:
parent
2fb48be0e3
commit
2427e8c0c0
1 changed files with 65 additions and 20 deletions
85
R/plots.R
85
R/plots.R
|
|
@ -1,3 +1,17 @@
|
||||||
|
#' Base color for the plots.
|
||||||
|
#' @noRd
|
||||||
|
base_color <- function() "#1964bf"
|
||||||
|
|
||||||
|
#' Transparent version of the base color.
|
||||||
|
#' @noRd
|
||||||
|
base_color_transparent <- function() "#1964bf80"
|
||||||
|
|
||||||
|
#' Color palette for gene sets.
|
||||||
|
#' @noRd
|
||||||
|
gene_set_color <- function(index) {
|
||||||
|
c("#FF7F00", "#4DAF4A", "#984EA3")[index]
|
||||||
|
}
|
||||||
|
|
||||||
#' Plot gene positions.
|
#' Plot gene positions.
|
||||||
#'
|
#'
|
||||||
#' This function requires the package `plotly`.
|
#' This function requires the package `plotly`.
|
||||||
|
|
@ -23,7 +37,7 @@ plot_positions <- function(species_ids, gene_sets) {
|
||||||
# Prefilter species.
|
# Prefilter species.
|
||||||
species <- geposan::species[id %chin% species_ids]
|
species <- geposan::species[id %chin% species_ids]
|
||||||
|
|
||||||
plot <- plotly::plot_ly(colors = "Set2") |>
|
plot <- plotly::plot_ly() |>
|
||||||
plotly::layout(
|
plotly::layout(
|
||||||
xaxis = list(
|
xaxis = list(
|
||||||
title = "Species",
|
title = "Species",
|
||||||
|
|
@ -36,7 +50,8 @@ plot_positions <- function(species_ids, gene_sets) {
|
||||||
data = species_max_distance,
|
data = species_max_distance,
|
||||||
x = ~species,
|
x = ~species,
|
||||||
y = ~max_distance,
|
y = ~max_distance,
|
||||||
color = "All genes"
|
name = "All genes",
|
||||||
|
marker = list(color = base_color())
|
||||||
)
|
)
|
||||||
|
|
||||||
if (length(gene_sets) > 0) {
|
if (length(gene_sets) > 0) {
|
||||||
|
|
@ -48,6 +63,8 @@ plot_positions <- function(species_ids, gene_sets) {
|
||||||
by.y = "id"
|
by.y = "id"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
index <- 1
|
||||||
|
|
||||||
for (gene_set_name in names(gene_sets)) {
|
for (gene_set_name in names(gene_sets)) {
|
||||||
gene_set <- gene_sets[[gene_set_name]]
|
gene_set <- gene_sets[[gene_set_name]]
|
||||||
|
|
||||||
|
|
@ -56,9 +73,14 @@ plot_positions <- function(species_ids, gene_sets) {
|
||||||
x = ~species,
|
x = ~species,
|
||||||
y = ~distance,
|
y = ~distance,
|
||||||
text = ~name,
|
text = ~name,
|
||||||
color = gene_set_name,
|
name = gene_set_name,
|
||||||
marker = list(size = 10, opacity = 0.66)
|
marker = list(
|
||||||
|
size = 10,
|
||||||
|
color = gene_set_color(index)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
index <- index + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,7 +107,7 @@ plot_rankings <- function(rankings, gene_sets) {
|
||||||
stop("Please install \"plotly\" to use this function.")
|
stop("Please install \"plotly\" to use this function.")
|
||||||
}
|
}
|
||||||
|
|
||||||
plot <- plotly::plot_ly(colors = "Set2") |>
|
plot <- plotly::plot_ly() |>
|
||||||
plotly::layout(
|
plotly::layout(
|
||||||
xaxis = list(tickvals = names(rankings)),
|
xaxis = list(tickvals = names(rankings)),
|
||||||
yaxis = list(title = "Score")
|
yaxis = list(title = "Score")
|
||||||
|
|
@ -100,12 +122,14 @@ plot_rankings <- function(rankings, gene_sets) {
|
||||||
data = ranking,
|
data = ranking,
|
||||||
x = ranking_name,
|
x = ranking_name,
|
||||||
y = ~score,
|
y = ~score,
|
||||||
color = "All genes",
|
name = "All genes",
|
||||||
type = "violin",
|
type = "violin",
|
||||||
spanmode = "hard",
|
spanmode = "hard",
|
||||||
points = FALSE,
|
points = FALSE,
|
||||||
showlegend = is_first,
|
showlegend = is_first,
|
||||||
hoverinfo = "skip"
|
hoverinfo = "skip",
|
||||||
|
line = list(color = base_color()),
|
||||||
|
fillcolor = base_color_transparent()
|
||||||
)
|
)
|
||||||
|
|
||||||
if (length(gene_sets) > 0) {
|
if (length(gene_sets) > 0) {
|
||||||
|
|
@ -116,6 +140,8 @@ plot_rankings <- function(rankings, gene_sets) {
|
||||||
by.y = "id"
|
by.y = "id"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
index <- 1
|
||||||
|
|
||||||
for (gene_set_name in names(gene_sets)) {
|
for (gene_set_name in names(gene_sets)) {
|
||||||
gene_set <- gene_sets[[gene_set_name]]
|
gene_set <- gene_sets[[gene_set_name]]
|
||||||
|
|
||||||
|
|
@ -123,7 +149,7 @@ plot_rankings <- function(rankings, gene_sets) {
|
||||||
data = gene_set_data[gene %chin% gene_set],
|
data = gene_set_data[gene %chin% gene_set],
|
||||||
x = ranking_name,
|
x = ranking_name,
|
||||||
y = ~score,
|
y = ~score,
|
||||||
color = gene_set_name,
|
name = gene_set_name,
|
||||||
text = ~name,
|
text = ~name,
|
||||||
customdata = ~percentile,
|
customdata = ~percentile,
|
||||||
hovertemplate = paste0(
|
hovertemplate = paste0(
|
||||||
|
|
@ -133,8 +159,13 @@ plot_rankings <- function(rankings, gene_sets) {
|
||||||
"<extra></extra>"
|
"<extra></extra>"
|
||||||
),
|
),
|
||||||
showlegend = is_first,
|
showlegend = is_first,
|
||||||
marker = list(size = 20, opacity = 0.66)
|
marker = list(
|
||||||
|
size = 10,
|
||||||
|
color = gene_set_color(index)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
index <- index + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -167,14 +198,14 @@ plot_scores <- function(ranking, gene_sets = NULL, max_rank = NULL) {
|
||||||
n_ranks <- nrow(ranking)
|
n_ranks <- nrow(ranking)
|
||||||
sample_ranking <- ranking[seq(1, n_ranks, 5)]
|
sample_ranking <- ranking[seq(1, n_ranks, 5)]
|
||||||
|
|
||||||
plot <- plotly::plot_ly(colors = "Set2") |>
|
plot <- plotly::plot_ly() |>
|
||||||
plotly::add_lines(
|
plotly::add_lines(
|
||||||
data = sample_ranking,
|
data = sample_ranking,
|
||||||
x = ~percentile,
|
x = ~percentile,
|
||||||
y = ~score,
|
y = ~score,
|
||||||
color = "All genes",
|
name = "All genes",
|
||||||
hoverinfo = "skip",
|
hoverinfo = "skip",
|
||||||
line = list(width = 4)
|
line = list(width = 4, color = base_color())
|
||||||
) |>
|
) |>
|
||||||
plotly::layout(
|
plotly::layout(
|
||||||
xaxis = list(
|
xaxis = list(
|
||||||
|
|
@ -193,6 +224,8 @@ plot_scores <- function(ranking, gene_sets = NULL, max_rank = NULL) {
|
||||||
by.y = "id"
|
by.y = "id"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
index <- 1
|
||||||
|
|
||||||
for (gene_set_name in names(gene_sets)) {
|
for (gene_set_name in names(gene_sets)) {
|
||||||
gene_set <- gene_sets[[gene_set_name]]
|
gene_set <- gene_sets[[gene_set_name]]
|
||||||
|
|
||||||
|
|
@ -200,7 +233,7 @@ plot_scores <- function(ranking, gene_sets = NULL, max_rank = NULL) {
|
||||||
data = gene_set_data[gene %chin% gene_set],
|
data = gene_set_data[gene %chin% gene_set],
|
||||||
x = ~percentile,
|
x = ~percentile,
|
||||||
y = ~score,
|
y = ~score,
|
||||||
color = gene_set_name,
|
name = gene_set_name,
|
||||||
text = ~name,
|
text = ~name,
|
||||||
customdata = ~rank,
|
customdata = ~rank,
|
||||||
hovertemplate = paste0(
|
hovertemplate = paste0(
|
||||||
|
|
@ -210,8 +243,13 @@ plot_scores <- function(ranking, gene_sets = NULL, max_rank = NULL) {
|
||||||
"Percentile: %{x:.2%}",
|
"Percentile: %{x:.2%}",
|
||||||
"<extra></extra>"
|
"<extra></extra>"
|
||||||
),
|
),
|
||||||
marker = list(size = 20, opacity = 0.66)
|
marker = list(
|
||||||
|
size = 10,
|
||||||
|
color = gene_set_color(index)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
index <- index + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -254,13 +292,14 @@ plot_boxplot <- function(ranking, gene_sets = NULL) {
|
||||||
stop("Please install \"plotly\" to use this function.")
|
stop("Please install \"plotly\" to use this function.")
|
||||||
}
|
}
|
||||||
|
|
||||||
plot <- plotly::plot_ly(colors = "Set2") |>
|
plot <- plotly::plot_ly() |>
|
||||||
plotly::add_boxplot(
|
plotly::add_boxplot(
|
||||||
data = ranking,
|
data = ranking,
|
||||||
x = "All genes",
|
x = "All genes",
|
||||||
y = ~score,
|
y = ~score,
|
||||||
color = "All genes",
|
name = "All genes",
|
||||||
showlegend = FALSE
|
showlegend = FALSE,
|
||||||
|
line = list(color = base_color())
|
||||||
) |>
|
) |>
|
||||||
plotly::layout(
|
plotly::layout(
|
||||||
xaxis = list(tickvals = c("All genes", names(gene_sets))),
|
xaxis = list(tickvals = c("All genes", names(gene_sets))),
|
||||||
|
|
@ -268,6 +307,8 @@ plot_boxplot <- function(ranking, gene_sets = NULL) {
|
||||||
)
|
)
|
||||||
|
|
||||||
if (length(gene_sets) > 0) {
|
if (length(gene_sets) > 0) {
|
||||||
|
index <- 1
|
||||||
|
|
||||||
for (gene_set_name in names(gene_sets)) {
|
for (gene_set_name in names(gene_sets)) {
|
||||||
gene_set <- gene_sets[[gene_set_name]]
|
gene_set <- gene_sets[[gene_set_name]]
|
||||||
|
|
||||||
|
|
@ -275,9 +316,12 @@ plot_boxplot <- function(ranking, gene_sets = NULL) {
|
||||||
data = ranking[gene %chin% gene_set],
|
data = ranking[gene %chin% gene_set],
|
||||||
x = gene_set_name,
|
x = gene_set_name,
|
||||||
y = ~score,
|
y = ~score,
|
||||||
color = gene_set_name,
|
name = gene_set_name,
|
||||||
showlegend = FALSE
|
showlegend = FALSE,
|
||||||
|
line = list(color = gene_set_color(index))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
index <- index + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -323,7 +367,8 @@ plot_chromosomes <- function(ranking) {
|
||||||
data = data,
|
data = data,
|
||||||
x = ~chromosome,
|
x = ~chromosome,
|
||||||
y = ~score,
|
y = ~score,
|
||||||
type = "bar"
|
type = "bar",
|
||||||
|
marker = list(color = base_color())
|
||||||
) |>
|
) |>
|
||||||
plotly::layout(
|
plotly::layout(
|
||||||
xaxis = list(
|
xaxis = list(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue