Skip to content

Commit 55fb139

Browse files
committed
Update AF trajectory panel and legend labels
1 parent 34c4b9c commit 55fb139

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

workflow/rules/report.smk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ rule af_trajectory_panel_plot:
277277
conda: "../envs/renv.yaml"
278278
params:
279279
design = config["PLOTS"],
280+
n_plot_columns = 3,
281+
plot_row_height_mm = 35,
282+
plot_width_mm = 159.2,
280283
random_color_seed = 7291,
281284
input:
282285
fmt_variants = OUTDIR/f"{OUTPUT_NAME}.variants.filled.dated.tsv",

workflow/scripts/report/af_trajectory_panel_plot.R

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,48 +21,52 @@ log_info("Reading subset of variants to represent")
2121
selected.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

2730
log_info("Plotting {length(selected.variants)} SNPs allele frequency trajectories in time")
2831
selected.colors <- sample(TRAJECTORY.PANEL.COLORS, length(selected.variants))
2932
log_debug("Selected color: {selected.colors}")
3033
p <- 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

5257
if (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

6165
ggsave(
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

Comments
 (0)