@@ -21,48 +21,52 @@ log_info("Reading subset of variants to represent")
2121selected.variants <- read_lines(snakemake @ input $ subset )
2222
2323# Set plot height depending on the number of SNPs assuming 4 columns in the plot
24- log_debug(" Calculating plot height" )
25- plot.height <- ceiling(length(selected.variants ) / 4 ) * 42
24+ plot.rows <- ceiling(
25+ length(selected.variants ) / snakemake @ params $ n_plot_columns
26+ )
27+ plot.height <- max(100 , plot.rows * snakemake @ params $ plot_row_height_mm )
28+ log_debug(" Setting total plot height to {plot.height} mm with {plot.rows} rows" )
2629
2730log_info(" Plotting {length(selected.variants)} SNPs allele frequency trajectories in time" )
2831selected.colors <- sample(TRAJECTORY.PANEL.COLORS , length(selected.variants ))
2932log_debug(" Selected color: {selected.colors}" )
3033p <- variants %> %
3134 filter(VARIANT_NAME %in% selected.variants ) %> %
35+ mutate(gPOS = reorder(paste0(" g." , POS ), POS )) %> %
3236 ggplot() +
3337 aes(
3438 x = interval ,
3539 y = ALT_FREQ ,
36- color = VARIANT_NAME
40+ color = reorder( glue :: glue( " {gPOS} \n { VARIANT_NAME} " ), POS )
3741 ) +
3842 scale_color_manual(values = selected.colors ) +
3943 geom_point() +
4044 geom_line() +
4145 theme(
4246 legend.position = " bottom" ,
43- legend.text = element_text(size = 9 )
47+ legend.text = element_text(size = 9 ),
48+ legend.title = element_blank(),
49+ legend.spacing.y = unit(3 , " mm" )
4450 ) +
4551 labs(
4652 x = " Days since first sample" ,
47- y = " Frequency" ,
48- color = " NV"
53+ y = " Frequency"
4954 ) +
5055 guides(color = guide_legend(ncol = 3 ))
5156
5257if (length(selected.variants ) > 1 ) {
5358 p <- p +
5459 facet_wrap(
55- vars(POS ),
56- nrow = ceiling(length(selected.variants ) / 4 ),
57- ncol = 4
60+ vars(gPOS ),
61+ ncol = snakemake @ params $ n_plot_columns
5862 )
5963}
6064
6165ggsave(
6266 filename = snakemake @ output [[" plot" ]],
6367 plot = p ,
64- width = 159.2 ,
65- height = max( 100 , plot.height ) ,
68+ width = snakemake @ params $ plot_width_mm ,
69+ height = plot.height ,
6670 units = " mm" ,
6771 dpi = 250
6872)
0 commit comments