ibdDraw: Colourised IBD plot

View source: R/ibdDraw.R

ibdDrawR Documentation

Colourised IBD plot

Description

This is a pedagogical tool for illustrating the concept of identity-by-descent, by representing the alleles in a pedigree by coloured points or letters. By default, the alleles are placed below each pedigree symbol, but this may be modified. (See examples.)

Usage

ibdDraw(
  x,
  alleles,
  symbol = c("point", "text"),
  pos = 1,
  cols = NULL,
  cex = NA,
  sep = 1,
  dist = 1,
  labs = FALSE,
  checkFounders = TRUE,
  checkParents = TRUE,
  ...
)

Arguments

x

A ped object.

alleles

A list of length pedsize(x). Each element should consist of one or two integers, representing different colours. Zeroes produce "greyed-out" alleles.

symbol

Either "point" or "text".

pos

A vector recycled to the length of labels(x), indicating allele placement relative to the pedigree symbols: 0 = inside; 1 = below; 2 = left; 3 = above; 4 = right. By default, all are placed below.

cols

A colour vector corresponding to the integers occurring in alleles.

cex

An expansion factor for the allele points/letters. Default: 3 for points and 2 for text.

sep

The separation between alleles within a pair, given as a multiple of the width of a pedigree symbol. Default is 1 when pos > 0 and 0.5 for pos = 0.

dist

The distance between pedigree symbols and the alleles, given as a multiple of symbol size. Default: 1. Ignored when pos = 0.

labs

A logical indicating if labels should be included.

checkFounders

A logical. If TRUE (default), a warning is issued if a founder has two equal alleles other than 0.

checkParents

A logical. If TRUE (default), a warning is issued if someone's alleles don't match those of the parents. This a superficial test and does not catch all Mendelian errors.

...

Further arguments passed on to plot.ped().

Value

The plot structure is returned invisibly.

See Also

pedtools::plot.ped(), ibdsim2::haploDraw()

Examples

op = par(no.readonly = TRUE)

###############################
# Example 1: A family quartet #
###############################

x = nuclearPed(2)
als = list(1:2, 3:4, c(1,3), c(2,3))

# Default options
ibdDraw(x, als)

# Nicer colors
cols = c(7, 3, 2, 4)
ibdDraw(x, als, cols = cols)

# Inside the pedigree symbols
ibdDraw(x, als, cols = cols, pos = 0, symbolsize = 2.5)

# Other placements
ibdDraw(x, als, cols = cols, pos = c(2, 3, 1, 4))

# Letters instead of points
ibdDraw(x, als, cols = cols, symbol = "text")

# Further arguments (note that `col` is an argument of `ped.plot()`)
ibdDraw(x, als, cols = cols, pos = 0, symbolsize = 2.5,
        labs = TRUE, fill = "lightgray")

# Mutations are warned about (unless `checkParents = FALSE`)
ibdDraw(x, alleles = list(1:2, 3:4, 5, 6))


##############################
# Example 2: Cousin pedigree #
##############################

x = cousinPed(1) |> swapSex(3) |> relabel()
als = list(1:2, 3:4, NULL, c(1,3), c(2,3), NULL, 3, 3)

cols = c(7, 3, 2, 4)
ibdDraw(x, als, cols = cols, dist = 0.8)
ibdDraw(x, als, cols = cols, dist = 0.8, symbol = "text")

# Alternative: 0's give greyed-out alleles
als2 = list(1:2, 3:4, c(0,0), c(1,3), c(2,3), c(0,0), c(0,3), c(3,0))

ibdDraw(x, als2, cols = cols, dist = 0.8)
ibdDraw(x, als2, cols = cols, dist = 0.8, symbol = "text")


############################
# Example 3: X inheritance #
############################

x = nuclearPed(2, sex = c(1, 2))
als = list(1, 2:3, 3, c(1, 3))
ibdDraw(x, als, cols = c(3, 7, 2))


#################################
# Example 4: mtDNA inheritance  #
#################################

x = linearPed(2, sex = 2)
als = list(1, 2, 3, 2, 2)
ibdDraw(x, als, cols = 2:4)


# Restore graphics parameters
par(op)


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