showInTriangle: Add points to the IBD triangle

View source: R/ibdTriangle.R

showInTriangleR Documentation

Add points to the IBD triangle

Description

Utility function for plotting kappa coefficients in the IBD triangle. This was previously only implemented as a base R plot, but is now also available in ggplot2 and plotly formats, controlled by the argument plotType. Labels are often easier to read in the two latter versions: The ggplot2 version uses ggrepel to separate labels, while plotly enables interactive exploration of the plot.

Usage

showInTriangle(
  kappa,
  plotType = c("base", "ggplot2", "plotly"),
  new = TRUE,
  ped = NULL,
  pedBL = c(0.5, 0.5),
  pedArgs = NULL,
  col = 6,
  cex = 1,
  pch = 4,
  lwd = 2,
  jitter = NULL,
  labels = NULL,
  colLab = col,
  cexLab = 0.8,
  labSep = "-",
  pos = 1,
  adj = NULL,
  keep.par = TRUE,
  ...
)

Arguments

kappa

Coordinates of points to be plotted in the IBD triangle. Valid input types are:

  • A numerical vector of length 2 (kappa0, kappa2) or 3 (kappa0, kappa1, kappa2). In the latter case kappa1 is ignored.

  • A matrix of data frame, whose column names must include either k0 and k2, kappa0 and kappa2, or ibd0 and ibd2.

  • A list (and not a data frame), in which case an attempt is made to bind the elements row-wise.

plotType

Either "base" (default), "ggplot2" or "plotly". Abbreviations are allowed.

new

A logical indicating if a new triangle should be drawn.

ped

A pedigree to be drawn in the upper right corner of the plot. Default: NULL. This only works when plotType is base or ggplot2.

pedBL

A vector of length two, with entries in ⁠[0,1]⁠, indicating the coordinates of the bottom left corner. Default: c(0.5, 0.5).

pedArgs

Plotting arguments for the inset pedigree. Default: NULL.

col, cex, pch, lwd

Parameters controlling the appearance of points.

jitter

A logical. If NULL (default), jittering is disabled for plotType's "base" or "ggplot2" and enabled for "plotly".

labels

A character of same length as the number of points, or a single logical TRUE or FALSE. If TRUE, labels are created by pasting columns id1 and id2 in kappa (if these exist) separated by labSep. By default, labels are disabled when plotType = "base", enabled if plotType = "ggplot2" and enabled (interactively) if plotType = "plotly".

colLab, cexLab, pos, adj

Parameters controlling the appearance of labels. Ignored when plotType = "plotly".

labSep

A string, by default "-".

keep.par

A logical. If TRUE (and plotType = "base"), the graphical parameters are not reset after plotting, which may be useful for adding additional annotation.

...

Plot arguments passed on to ibdTriangle().

Value

If plotType = 'base', the function returns NULL; otherwise the plot object.

See Also

ibdTriangle(), kappaIBD()

Examples

showInTriangle(c(3/8, 1/8), label = "3/4 siblings", pos = 1)

# With inset pedigree
x = doubleCousins(1, 0, half2 = TRUE)
showInTriangle(c(3/8, 1/8), label = "3/4 siblings", pos = 1,
               ped = x, pedArgs = list(hatched = 6:7))

# All pairs
k = kappaIBD(x)
showInTriangle(k, labels = TRUE, pos = 1:4, ped = x)

# With jitter and variable colors
showInTriangle(k, labels = TRUE, pos = 1:4, jitter = TRUE, col = 1:7, ped = x)

# Separate labels (requires ggplot2 + ggrepel)
# showInTriangle(k, plot = "ggplot2", col = 2:8, ped = x)

# Interactive plot (requires plotly)
# showInTriangle(k, plot = "plotly", col = 2:8, pch = 0)


magnusdv/ribd documentation built on March 29, 2024, 5:20 a.m.