mirror of
https://github.com/johrpan/ubigen.git
synced 2025-10-26 19:57:24 +01:00
Show percentiles in overview plot
This commit is contained in:
parent
1bd5e41c8f
commit
7f67dec72e
1 changed files with 58 additions and 4 deletions
62
R/plots.R
62
R/plots.R
|
|
@ -15,20 +15,38 @@ overview_plot <- function(ranked_data,
|
|||
nrow(ranked_data),
|
||||
sample_proportion * nrow(ranked_data)
|
||||
)],
|
||||
x = ~rank,
|
||||
x = ~percentile,
|
||||
y = ~score,
|
||||
hoverinfo = "skip"
|
||||
) |>
|
||||
plotly::layout(
|
||||
xaxis = list(title = "Ranks"),
|
||||
yaxis = list(title = "Score")
|
||||
xaxis = list(
|
||||
title = "Percentile",
|
||||
autorange = "reversed",
|
||||
tickformat = ".1%"
|
||||
),
|
||||
yaxis = list(title = "Score"),
|
||||
shapes = list(
|
||||
vline(0.95),
|
||||
vline(0.75),
|
||||
vline(0.50),
|
||||
vline(0.25),
|
||||
vline(0.05)
|
||||
),
|
||||
annotations = list(
|
||||
vlineannotation(0.95),
|
||||
vlineannotation(0.75),
|
||||
vlineannotation(0.50),
|
||||
vlineannotation(0.25),
|
||||
vlineannotation(0.05)
|
||||
)
|
||||
)
|
||||
|
||||
if (length(highlighted_genes) > 0) {
|
||||
figure <- figure |>
|
||||
plotly::add_markers(
|
||||
data = ranked_data[gene %chin% highlighted_genes],
|
||||
x = ~rank,
|
||||
x = ~percentile,
|
||||
y = ~score,
|
||||
text = ~ glue::glue(
|
||||
"<b>{hgnc_name}</b><br>",
|
||||
|
|
@ -121,3 +139,39 @@ scores_plot <- function(ranked_data, highlighted_genes = NULL, ranks = 1000) {
|
|||
dragmode = "select"
|
||||
)
|
||||
}
|
||||
|
||||
#' Helper function for creating a vertical line for plotly.
|
||||
#' @noRd
|
||||
vline <- function(x) {
|
||||
list(
|
||||
type = "line",
|
||||
y0 = 0,
|
||||
y1 = 1,
|
||||
yref = "paper",
|
||||
x0 = x,
|
||||
x1 = x,
|
||||
line = list(
|
||||
color = "#00000080",
|
||||
opacity = 0.5,
|
||||
dash = "dot"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
#' Helper function for creating annotations for lines created using [vline()].
|
||||
#' @noRd
|
||||
vlineannotation <- function(x) {
|
||||
list(
|
||||
text = glue::glue("{round(x * 100)}%"),
|
||||
showarrow = FALSE,
|
||||
yref = "paper",
|
||||
x = x,
|
||||
y = 1,
|
||||
xanchor = "left",
|
||||
xshift = 4,
|
||||
align = "left",
|
||||
font = list(
|
||||
color = "#00000080"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue