mirror of
https://github.com/johrpan/geposanui.git
synced 2025-10-26 19:27:24 +01:00
Enhance scatter plot
This commit is contained in:
parent
1c43433600
commit
363dee2cbd
2 changed files with 58 additions and 26 deletions
|
|
@ -2,31 +2,63 @@ library(data.table)
|
||||||
library(ggplot2)
|
library(ggplot2)
|
||||||
|
|
||||||
#' Draw a scatter plot containing gene positions.
|
#' Draw a scatter plot containing gene positions.
|
||||||
scatter_plot <- function(gene_ids, data) {
|
#'
|
||||||
plot <- ggplot() +
|
#' @param input Input data from [`load_input()`].
|
||||||
|
#' @param results Results from [`process_input()`].
|
||||||
|
scatter_plot <- function(gene_ids, input, results) {
|
||||||
|
if (length(gene_ids) < 1) {
|
||||||
|
return(ggplot())
|
||||||
|
}
|
||||||
|
|
||||||
|
# Exclude species with naturally or artificially short chromosomes as well
|
||||||
|
# as non-replicatively aging species.
|
||||||
|
# TODO: Sync with process_input().
|
||||||
|
species <- input$species[
|
||||||
|
median_distance >= 7500000 & group == "replicative"
|
||||||
|
]
|
||||||
|
|
||||||
|
species_ids <- species[, id]
|
||||||
|
|
||||||
|
data <- merge(
|
||||||
|
input$genes[id %in% gene_ids, .(id, name)],
|
||||||
|
input$distances[species %in% species_ids],
|
||||||
|
by.x = "id", by.y = "gene"
|
||||||
|
)
|
||||||
|
|
||||||
|
for (gene_id in gene_ids) {
|
||||||
|
cluster_species <- unlist(results[gene == gene_id, cluster_species])
|
||||||
|
data[id == gene_id, in_cluster := species %in% cluster_species]
|
||||||
|
}
|
||||||
|
|
||||||
|
ggplot(data) +
|
||||||
scale_x_discrete(
|
scale_x_discrete(
|
||||||
name = "Species",
|
name = "Species",
|
||||||
breaks = data$species$id,
|
breaks = species$id,
|
||||||
labels = data$species$label
|
labels = species$label
|
||||||
|
) +
|
||||||
|
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") +
|
||||||
|
scale_shape_discrete(
|
||||||
|
name = "Part of cluster",
|
||||||
|
breaks = c(TRUE, FALSE),
|
||||||
|
labels = c("Yes", "No")
|
||||||
) +
|
) +
|
||||||
scale_y_continuous(name = "Distance to telomeres [Mbp]")
|
|
||||||
|
|
||||||
colors <- rainbow(length(gene_ids))
|
|
||||||
|
|
||||||
for (i in seq_len(length(gene_ids))) {
|
|
||||||
gene_id <- gene_ids[i]
|
|
||||||
|
|
||||||
plot <- plot +
|
|
||||||
geom_point(
|
geom_point(
|
||||||
data$distances[gene == gene_id],
|
|
||||||
mapping = aes(
|
mapping = aes(
|
||||||
x = species,
|
x = species,
|
||||||
y = distance / 1000000,
|
y = distance / 1000000,
|
||||||
|
color = name,
|
||||||
|
shape = in_cluster
|
||||||
),
|
),
|
||||||
color = colors[i],
|
size = 5
|
||||||
size = 4
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
plot
|
|
||||||
}
|
|
||||||
2
server.R
2
server.R
|
|
@ -37,6 +37,6 @@ server <- function(input, output) {
|
||||||
|
|
||||||
output$scatter <- renderPlot({
|
output$scatter <- renderPlot({
|
||||||
gene_ids <- filtered()[input$genes_rows_selected, gene]
|
gene_ids <- filtered()[input$genes_rows_selected, gene]
|
||||||
scatter_plot(gene_ids, data)
|
scatter_plot(gene_ids, data, results)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue