geposanui/scatter_plot.R

32 lines
796 B
R
Raw Normal View History

2021-06-24 22:38:16 +02:00
library(data.table)
library(ggplot2)
#' Draw a scatter plot containing gene positions.
scatter_plot <- function(gene_ids, data) {
plot <- ggplot() +
scale_x_discrete(
2021-06-24 22:38:16 +02:00
name = "Species",
breaks = data$species$id,
labels = data$species$label
2021-06-24 22:38:16 +02:00
) +
scale_y_continuous(name = "Distance to telomeres [Mbp]")
2021-06-24 22:38:16 +02:00
colors <- rainbow(length(gene_ids))
for (i in seq_len(length(gene_ids))) {
gene_id <- gene_ids[i]
plot <- plot +
geom_point(
data$distances[gene == gene_id],
2021-06-24 22:38:16 +02:00
mapping = aes(
x = species,
2021-06-24 22:38:16 +02:00
y = distance / 1000000,
),
color = colors[i],
size = 4
2021-06-24 22:38:16 +02:00
)
}
plot
}