Scatter Plot Module
scatter.RmdDeveloper’s Guide to the
qtl2shiny Package
Overview
The Scatter Plot panel allows researchers to interactively explore and visualize correlations between numeric variables (phenotypes) across study subjects. To aid in dissecting genetic architecture, the module enables coloring, shaping, and faceting points by Strain Distribution Patterns (SDPs), genotype probability patterns, sex, or diet covariates.
It coordinates two primary Shiny modules:
-
scatterApp: The top-level panel coordinator that loads founder probabilities, queries variants, aligns phenotype columns with ancestral patterns/covariates, and packages the download interface. -
scatterPlotApp: The reusable generic plotting submodule that configures plot aesthetics, draws regression lines, handles interactive plotly/ggplotly toggling, and displays the final graphic.
Module Hierarchy & Entrypoints
-
Top-Level Container:
- Standalone Application:
scatterApp() - Server Module:
scatterServer(id, hotspot_list, pattern_list, snp_list, pairprobs_obj, project_df) - UI Input:
scatterInput(id) - UI Output:
scatterOutput(id)
- Standalone Application:
-
Sub-Modules:
-
Generic Scatter Plot (
scatterPlotApp): Standard plotting engine. Server:scatterPlotServer(id, plot_df, x_label, y_label). UI Input:scatterPlotInput(id). UI Output:scatterPlotOutput(id).
-
Generic Scatter Plot (
1. Top-Level Container (scatterApp)
The scatterApp module coordinates data collection, input
routing, and download packaging for the scatter panel.
Server Logic & Reactive Flow (scatterServer)
-
Probabilities & Genotypes:
- Calls
genoDataServer("geno_list", ...)to extract diplotype probabilities at the active marker coordinatepos_Mbp. - Obtains the genotype table, extracting ancestral alleles and Strain Distribution Patterns (SDPs).
- Calls
-
Tidy Merging:
- Gathers selected phenotype values (from X and Y variable dropdown
inputs) via
hotspot_list$pheno_mx(). - Factorizes scan patterns and filters out unmapped covariates,
keeping only the selected patterns,
sex, anddietfor aesthetic options. - Combines coordinates, patterns, and covariates into a single tidy
reactive data frame (
scatter_df).
- Gathers selected phenotype values (from X and Y variable dropdown
inputs) via
-
Axis Labeling:
- Passes the raw phenotype names
shiny::reactive(input$x_var)andshiny::reactive(input$y_var)toscatterPlotServer()to dynamically apply custom, user-friendly axis labels.
- Passes the raw phenotype names
2. Reusable Scatter Plot Module (scatterPlotApp)
The scatterPlotApp module is a generic, reusable
visualization engine that plots coordinate pairs from any reactive data
frame containing columns x and y.
Plot Customization & Aesthetics
-
Hollow/Open Shapes:
- To prevent overplotting and maintain point visibility when multiple
samples overlap, points default to shape
1(open/hollow circle). - Mapped discrete shapes (e.g.
shape_by) utilize hollow shape codes (1,2,5,0,6…) to keep categories distinct.
- To prevent overplotting and maintain point visibility when multiple
samples overlap, points default to shape
-
Bolder Outlines:
- Configures
stroke = 1.5on all point geometries, widening the circle and symbol outlines to remain highly legible when combined with transparency (alpha).
- Configures
-
Regression Lines:
- Automatically draws solid regression lines
(
linetype = "solid") underneath scatter symbols, preventing line overlays from obscuring point centers. - Automatically groups and draws separate regression lines when a
coloring aesthetic (
color_by) is selected.
- Automatically draws solid regression lines
(
-
Robust Faceting:
- Since strain distribution pattern names can contain colons
":"(e.g.,"A:B"), faceting avoids formula parsing syntax (which interprets colons as interaction variables). It instead uses the tidyverse data pronoun reference:facet_wrap(ggplot2::vars(.data[[facet_var]]))
- Since strain distribution pattern names can contain colons