| 
									
										
										
										
											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() + | 
					
						
							| 
									
										
										
										
											2021-08-16 17:21:01 +02:00
										 |  |  |         scale_x_discrete( | 
					
						
							| 
									
										
										
										
											2021-06-24 22:38:16 +02:00
										 |  |  |             name = "Species", | 
					
						
							| 
									
										
										
										
											2021-08-16 17:21:01 +02:00
										 |  |  |             breaks = data$species$id, | 
					
						
							|  |  |  |             labels = data$species$label | 
					
						
							| 
									
										
										
										
											2021-06-24 22:38:16 +02:00
										 |  |  |         ) + | 
					
						
							| 
									
										
										
										
											2021-08-16 17:21:01 +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( | 
					
						
							| 
									
										
										
										
											2021-08-16 17:21:01 +02:00
										 |  |  |                 data$distances[gene == gene_id], | 
					
						
							| 
									
										
										
										
											2021-06-24 22:38:16 +02:00
										 |  |  |                 mapping = aes( | 
					
						
							| 
									
										
										
										
											2021-08-16 17:21:01 +02:00
										 |  |  |                     x = species, | 
					
						
							| 
									
										
										
										
											2021-06-24 22:38:16 +02:00
										 |  |  |                     y = distance / 1000000, | 
					
						
							|  |  |  |                 ), | 
					
						
							| 
									
										
										
										
											2021-08-16 17:21:01 +02:00
										 |  |  |                 color = colors[i], | 
					
						
							|  |  |  |                 size = 4 | 
					
						
							| 
									
										
										
										
											2021-06-24 22:38:16 +02:00
										 |  |  |             ) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     plot | 
					
						
							|  |  |  | } |