plotPolarized: Plot Polarized Genotypes

View source: R/plotPolarized.r

plotPolarizedR Documentation

Plot Polarized Genotypes

Description

Plots genotypes that can be optionally polarized and visualized as either a rectangular or circular (iris-style) plot.

Usage

plotPolarized(
  genotypes,
  HI,
  cols = c("#FFFFFF", "#800080", "#FFE500", "#008080"),
  type = "rectangle",
  showProgress = FALSE,
  addMarkerAxis = FALSE,
  ...
)

Arguments

genotypes

A character matrix with _012 encoding of genotypes. Rows represent individuals, columns represent markers.

HI

A numeric vector of hybrid indices, one per individual (row in genotypes).

cols

A vector of four colors representing: missing data, homozygotes for 0, heterozygotes, and homozygotes for 2 (in that order).

type

Character string specifying the layout of the plot. Accepted values are "rectangle", "iris", or "circular". Partial matching is allowed.

showProgress

Logical. If TRUE, prints a percentage indicator as individuals are plotted (applies only to iris plots).

addMarkerAxis

Logical. If TRUE, a default marker axis is added below the genotype matrix (in rectangular layout) or as a radial axis (in circular layout). Requires either includedSites or axisInfo. For full customization of the axis (e.g., styling, label orientation), use plotMarkerAxis manually.

...

Additional arguments passed to internal plotting functions. See Details.

Details

To import and polarize genotypes, use importPolarized.

When using diem, the hybrid indices (HI) are saved in the file "HIwithOptimalPolarities.txt". Alternatively, you can compute HI directly from polarized genotypes (see Examples).

By default, the function plots colored tick marks for individuals, with a color change at the steepest hybrid index gradient. The second and fourth colors in cols are used for these ticks. You can:

  • Disable the ticks using tick = FALSE,

  • Provide a vector of tick colors (must match the number of individuals), ordered according to order(HI),

  • Provide individual labels (e.g., accession numbers) in the same order as the rows in genotypes.

If addMarkerAxis = TRUE, you must also supply either:

  • includedSites — a file path containing columns CHROM and POS, or

  • axisInfo — a precomputed axis information list, as described in plotMarkerAxis.

Additional graphical parameters are passed to internal calls to image(), axis(), and plotMarkerAxis(). The following arguments are supported:

Image arguments: zlim, xlim, ylim, add, xaxs, yaxs, xlab, ylab, breaks, useRaster, asp, cex, cex.lab, cex.main, cex.sub, axes, col.axis, cex.axis, family, font, font.axis, font.lab, font.main, font.sub, lab, xpd.

Axis arguments: side, at, col.ticks, labels, las, tick, line, pos, outer, font, lty, lwd, lwd.ticks, hadj, padj, gap.axis, xpd, cex.axis.

Value

No return value. Called for its side effects - a visual plot of polarized genotypes. In the default color scheme:

  • Purple and teal represent homozygotes (0 and 2),

  • Yellow represents heterozygotes (1),

  • White indicates missing or undetermined genotypes (⁠_⁠). Individuals are ordered by increasing HI (bottom up in rectangular plots and inside out in circular plots).

See Also

plotMarkerAxis for adding chromosome information as a custom axis to the rectangle genotype plot.

Examples

gen <- importPolarized(
  file = system.file("extdata", "data7x10.txt", package = "diemr"),
  changePolarity = c(TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE),
  ChosenInds = 1:7
)

h <- apply(gen, 1, FUN = function(x) pHetErrOnStateCount(sStateCount(x)))[1, ]

plotPolarized(genotypes = gen, HI = h)

# Incorrect tick color order
plotPolarized(gen, h, col.ticks = c(rep("purple", 5), "green", "purple"), lwd = 3)

# Correct tick color order
plotPolarized(gen, h, col.ticks = c(rep("purple", 5), "green", "purple")[order(h)], lwd = 3)

# Correct individual label order
plotPolarized(gen, h, labels = c(paste("purple", 1:5), "green 1", "purple 6"))
plotPolarized(gen, h, labels = c(paste("purple", 1:5), "green 1", "purple 6"), type = "iris")

diemr documentation built on Dec. 11, 2025, 5:07 p.m.