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]")
)
}

View file

@ -148,7 +148,7 @@ server <- function(input, output) {
)
})
output$scatter <- renderPlot({
output$scatter <- renderPlotly({
results <- results()
gene_ids <- results[input$genes_rows_selected, gene]

14
ui.R
View file

@ -62,16 +62,10 @@ ui <- fluidPage(
p("This plot shows the selected genes' distance to the telomeres \
across species. It visualizes how certain genes have \
evolutionary conserved positions."),
div(
style = "overflow-x: auto",
div(
style = "min-width: 1400px",
plotOutput(
"scatter",
width = "100%",
height = "600px"
)
)
plotlyOutput(
"scatter",
width = "100%",
height = "600px"
),
h3("Gene set enrichment analysis"),
checkboxInput(