plot_baf_with_ploidy_guides: Plot BAF-derived X–Y scatter with ploidy dosage guides...

View source: R/plots_standardization.R

plot_baf_with_ploidy_guidesR Documentation

Plot BAF-derived X–Y scatter with ploidy dosage guides (optional sample highlighting)

Description

Reconstructs Cartesian coordinates from standardized B-allele frequency (BAF) and read depth 'R' as X = (1 - \mathrm{BAF}) \cdot R and Y = \mathrm{BAF} \cdot R, then draws a scatter plot with expected dosage guide lines for a given ploidy. You can color all samples by 'SampleName' or highlight a single sample and render the rest in gray. Samples with no plottable points (non-finite coordinates) are automatically omitted from the legend.

Usage

plot_baf_with_ploidy_guides(
  df,
  ploidy = 2,
  fallback_to_ratio = FALSE,
  normalize_depth = TRUE,
  radius = NULL,
  sample = NULL,
  highlight_color = "tomato",
  other_color = "grey75"
)

Arguments

df

A 'data.frame' with required columns: - 'baf' (numeric in \[0,1\]): standardized B-allele frequency. - 'R' (numeric): total read depth. - 'SampleName' (character/factor): sample label used for coloring. Optional column 'ratio' may be present and used when 'fallback_to_ratio = TRUE'.

ploidy

Integer (>= 2). Ploidy used to compute dosage guide lines.

fallback_to_ratio

Logical. If 'TRUE', fill 'NA' values in 'baf' with corresponding values from 'ratio' (when available). Default: 'FALSE'.

normalize_depth

Logical. If 'TRUE', place all points on a common radius (see ‘radius'); if 'FALSE', use each point’s 'R'. Default: 'TRUE'.

radius

Numeric scalar radius to use when 'normalize_depth = TRUE'. If 'NULL', uses 'stats::median(df$R, na.rm = TRUE)'. Ignored when 'normalize_depth = FALSE'. Default: 'NULL'.

sample

Character. Either '"all"' to color all samples by 'SampleName', or the name of a single sample to highlight. Default: '"all"'.

highlight_color

Color for the highlighted sample when 'sample != "all"'. Default: '"tomato"'.

other_color

Color for non-highlighted samples when 'sample != "all"'. Default: '"grey75"'.

Details

* Coordinates are computed from BAF and depth: X=(1-\mathrm{BAF})R, Y=\mathrm{BAF}R. * If 'fallback_to_ratio = TRUE' and 'baf' is 'NA', values from 'ratio' are used. The effective BAF is clamped into \[0, 1\]. * When 'normalize_depth = TRUE', all points are projected to the same radius (depth) given by 'radius' (or 'stats::median(R)' if 'radius' is 'NULL'), which emphasizes dosage bands rather than depth variation. When 'FALSE', each point uses its own 'R'. * Dosage guide lines are drawn for d \in \{0,\dots,\mathrm{ploidy}\}: 'd = 0' → horizontal line 'Y = 0'; 'd = ploidy' → vertical line 'X = 0'; intermediate dosages are lines through the origin with slope (d/\mathrm{ploidy}) / (1 - d/\mathrm{ploidy}). * The legend is built from actually plotted rows only; if a requested 'sample' has no plottable points, it is omitted from the legend. * Uses a fixed aspect ratio ('coord_fixed') so x and y units are comparable.

Value

A **ggplot** object.

See Also

[plot_xy_with_ploidy_guides()] for plotting raw 'X'/'Y' counts with guides.


Qploidy documentation built on July 11, 2026, 5:06 p.m.