2010-06-30

Drawing pedigree examples using the kinship R package

I have previously provided sort of an overview about plotting the pedigrees, then specifically using the Graphiviz, while I have lately used the TikZ LaTeX (see slides 11-15) system (see more example). The later gives great (beautiful) results, but at the cost of writing TikZ code - it is not that horible, just time consuming - the same applies to Graphviz. Is there a quick way to plot a pedigree if we already have the data in the file. It is possible to do it in R using the kinship package. Here is an example:
ped <- data.frame( id=c( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
fid=c( 0, 0, 0, 3, 3, 5, 3, 6, 6, 0, 9),
mid=c( 0, 0, 0, 2, 1, 4, 4, 7, 7, 0, 10),
sex=c( 2, 2, 1, 2, 1, 1, 2, 1, 1, 2, 2),
aff=0)
ped[11, "aff"] <- 1

library(package="kinship")
ped <- with(ped, pedigree(id=id, dadid=fid, momid=mid, sex=sex, affected=aff))
plot(ped)
Which gives the following result. It is not great, but it is informative and easy to do. From a practical point of implementation all pedigree members need to have both parents known or no parents known.


No comments: