Port scatter plot to plotly

This commit is contained in:
Elias Projahn 2021-10-15 12:24:28 +02:00
parent fcd9b4ee05
commit 114193506b
3 changed files with 24 additions and 42 deletions

View file

@ -1,5 +1,5 @@
library(data.table)
library(ggplot2)
library(plotly)
#' Draw a scatter plot containing gene positions.
#'
@ -8,10 +8,6 @@ library(ggplot2)
#' @param genes Genes to be displayed.
#' @param distances Distance data to display.
scatter_plot <- function(results, species, genes, distances) {
if (nrow(genes) < 1) {
return(ggplot())
}
species_ids <- species[, id]
data <- merge(
@ -20,30 +16,22 @@ scatter_plot <- function(results, species, genes, distances) {
by.x = "id", by.y = "gene"
)
ggplot(data) +
scale_x_discrete(
name = "Species",
breaks = species$id,
labels = species$name
) +
scale_y_continuous(
name = "Distance to telomeres [Mbp]",
limits = function(x) {
if (x[2] < 15) {
c(0, 15)
} else {
x
}
}
) +
scale_color_discrete(name = "Gene") +
geom_point(
mapping = aes(
x = species,
y = distance / 1000000,
color = name
),
size = 5
) +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1))
data[name == "", name := "Unknown"]
plot_ly(
data = data,
x = ~species,
y = ~distance,
color = ~id,
name = ~name,
type = "scatter",
mode = "markers"
) |> layout(
xaxis = list(
title = "Species",
tickvals = species_ids,
ticktext = species[, name]
),
yaxis = list(title = "Distance to telomeres [Bp]")
)
}