mirror of
https://github.com/johrpan/ubigen.git
synced 2025-10-26 19:57:24 +01:00
Add score distribution plot
This commit is contained in:
parent
276730f217
commit
1a47b30dbf
3 changed files with 55 additions and 1 deletions
43
R/server.R
43
R/server.R
|
|
@ -21,9 +21,52 @@ server <- function(input, output) {
|
|||
data
|
||||
})
|
||||
|
||||
output$scores_plot <- plotly::renderPlotly(scores_plot(ranked_data()))
|
||||
output$ranked_data <- DT::renderDataTable(genes_table(ranked_data()))
|
||||
}
|
||||
|
||||
#' Create plot showing the distribution of scores using `plotly`.
|
||||
#'
|
||||
#' @param ranked_data Data on genes with precomputed ranks.
|
||||
#' @param ranks How may ranks the x-axis should include. If this parameter is
|
||||
#' `NULL`, all ranks will be shown.
|
||||
#'
|
||||
#' @return A `plotly` figure for rendering.
|
||||
#' @noRd
|
||||
scores_plot <- function(ranked_data, ranks = 1000) {
|
||||
data <- if (is.null(ranks)) {
|
||||
ranked_data
|
||||
} else {
|
||||
ranked_data[1:ranks]
|
||||
}
|
||||
|
||||
ranks_label <- if (is.null(ranks)) {
|
||||
"Ranks"
|
||||
} else {
|
||||
glue::glue("Ranks (1 to {ranks})")
|
||||
}
|
||||
|
||||
plotly::plot_ly() |>
|
||||
plotly::add_markers(
|
||||
data = data,
|
||||
x = ~rank,
|
||||
y = ~score,
|
||||
text = ~hgnc_name,
|
||||
customdata = ~percentile,
|
||||
hovertemplate = paste0(
|
||||
"<b>%{text}</b><br>",
|
||||
"Rank: %{x}<br>",
|
||||
"Score: %{y:.2}<br>",
|
||||
"Percentile: %{customdata:.2%}",
|
||||
"<extra></extra>"
|
||||
)
|
||||
) |>
|
||||
plotly::layout(
|
||||
xaxis = list(title = ranks_label),
|
||||
yaxis = list(title = "Score")
|
||||
)
|
||||
}
|
||||
|
||||
#' Create a displayable data table from the gene results data.
|
||||
#' @noRd
|
||||
genes_table <- function(data) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue