diff --git a/scatter_plot.R b/scatter_plot.R index ee8f28c..3c1aecd 100644 --- a/scatter_plot.R +++ b/scatter_plot.R @@ -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]") + ) } \ No newline at end of file diff --git a/server.R b/server.R index d302ac8..59070a1 100644 --- a/server.R +++ b/server.R @@ -148,7 +148,7 @@ server <- function(input, output) { ) }) - output$scatter <- renderPlot({ + output$scatter <- renderPlotly({ results <- results() gene_ids <- results[input$genes_rows_selected, gene] diff --git a/ui.R b/ui.R index 4e03b5b..5e72b39 100644 --- a/ui.R +++ b/ui.R @@ -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(