Skip to content

Commit

Permalink
return all info from plotPedigree
Browse files Browse the repository at this point in the history
  • Loading branch information
timflutre-perso committed Oct 11, 2016
1 parent 65d76f3 commit 05ade62
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rutilstimflutre
Title: Timothee Flutre's personal R code
Version: 0.80.1
Version: 0.81.0
Authors@R: c(
person("Timothee", "Flutre", email="[email protected]", role=c("aut", "ctb", "cre")),
person("Carbonetto", "Peter", role="aut", comment="function from varbvs example"),
Expand Down
46 changes: 26 additions & 20 deletions R/quantgen.R
Original file line number Diff line number Diff line change
Expand Up @@ -4063,6 +4063,7 @@ readBiomercator <- function(file){
##' @param fathers identifiers of their father; can be NA
##' @param generations should start at 0
##' @param sexes "F" for female (circle), "M" for male (square) and "H" for hermaphrodite (triangle); can also be NA (no shape)
##' @param plot.it if TRUE, the pedigree will be plotted
##' @param edge.col.mother see ?igraph.plotting
##' @param edge.col.father see ?igraph.plotting
##' @param vertex.label.color see ?igraph.plotting
Expand All @@ -4074,16 +4075,18 @@ readBiomercator <- function(file){
##' @param edge.arrow.width see ?igraph.plotting
##' @param edge.arrow.size see ?igraph.plotting
##' @param ... other plotting options; see ?plot.igraph and ?igraph.plotting
##' @return invisible pedigree as an "igraph" object
##' @return invisible list with objects required to plot the pedigree
##' @author Timothee Flutre
##' @export
plotPedigree <- function(inds, mothers, fathers, generations, sexes=NULL,
plot.it=TRUE,
edge.col.mother="black", edge.col.father="darkgrey",
vertex.label.color="darkblue", vertex.color="white",
vertex.size=20, vertex.shape="none",
vertex.label.family="Helvetica", mult.edge.curve=0.25,
edge.arrow.width=0.75, edge.arrow.size=0.75,
...){
requireNamespace("igraph")
stopifnot(is.vector(inds),
is.vector(mothers),
is.vector(fathers),
Expand Down Expand Up @@ -4182,18 +4185,19 @@ plotPedigree <- function(inds, mothers, fathers, generations, sexes=NULL,
## set plot coordinates for vertices
coords <- matrix(data=NA, nrow=length(inds), ncol=2,
dimnames=list(inds, c("x", "y")))
coords[,2] <- max(generations) - generations
## coords[,1] <- order(generations, partial=order(inds, decreasing=TRUE)) -
coords[, "y"] <- max(generations) - generations
## coords[, "x"] <- order(generations, partial=order(inds, decreasing=TRUE)) -
## cumsum(c(0, table(generations)))[generations + 1]
coords[,1] <- order(generations) -
coords[, "x"] <- order(generations) -
cumsum(c(0, table(generations)))[generations + 1]
coords[nrow(coords):1,1] <- unlist(tapply(coords[,1], coords[,2], function(x){
if(length(x) == 1){
x <- 0
} else
x <- rev(scale(x))
return(x)
}))
coords[nrow(coords):1, "x"] <-
unlist(tapply(coords[, "x"], coords[,"y"], function(x){
if(length(x) == 1){
x <- 0
} else
x <- rev(scale(x))
return(x)
}))

## set edge color depending on parental sex
nb.rel.mother <- sum(! is.na(mothers))
Expand All @@ -4211,13 +4215,15 @@ plotPedigree <- function(inds, mothers, fathers, generations, sexes=NULL,
}

## plot, finally
igraph::plot.igraph(x=ped.graph,
layout=coords,
edge.color=edge.cols,
edge.curved=edge.curvatures,
edge.arrow.width=edge.arrow.width,
edge.arrow.size=edge.arrow.size,
...)

invisible(ped.graph)
if(plot.it)
igraph::plot.igraph(x=ped.graph,
layout=coords,
edge.color=edge.cols,
edge.curved=edge.curvatures,
edge.arrow.width=edge.arrow.width,
edge.arrow.size=edge.arrow.size,
...)

invisible(list(graph=ped.graph, layout=coords, edge.color=edge.cols,
edge.curved=edge.curvatures))
}
6 changes: 4 additions & 2 deletions man/plotPedigree.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 05ade62

Please sign in to comment.