geposanui/R/scatter_plot.R

34 lines
866 B
R
Raw Normal View History

2021-10-20 15:34:52 +02:00
# Draw a scatter plot containing gene positions.
#
# @param results Results from [`process_input()`].
# @param species Species to be displayed.
# @param genes Genes to be displayed.
scatter_plot <- function(results, species, genes) {
2021-08-26 12:50:03 +02:00
species_ids <- species[, id]
2021-06-24 22:38:16 +02:00
2021-08-26 12:50:03 +02:00
data <- merge(
2021-09-16 00:06:54 +02:00
genes[, .(id, name)],
2021-10-20 15:34:52 +02:00
geposan::distances[species %in% species_ids],
2021-08-26 12:50:03 +02:00
by.x = "id", by.y = "gene"
)
2021-06-24 22:38:16 +02:00
2021-10-15 12:24:28 +02:00
data[name == "", name := "Unknown"]
2021-10-20 15:34:52 +02:00
plotly::plot_ly(
2021-10-15 12:24:28 +02:00
data = data,
x = ~species,
y = ~distance,
color = ~id,
name = ~name,
type = "scatter",
mode = "markers"
2021-10-20 15:34:52 +02:00
) |> plotly::layout(
2021-10-15 12:24:28 +02:00
xaxis = list(
title = "Species",
tickvals = species_ids,
ticktext = species[, name]
),
yaxis = list(title = "Distance to telomeres [Bp]")
)
2021-10-20 15:34:52 +02:00
}