How to plot family tree in R -
i've been searching around how plot family tree couldn't find reproduce. i've been looking in hadley's book ggplot same thing.
i want plot family tree having source dataframe similar this:
dput(head(familytree)) structure( list( id = 1:6, cnp = c("11", na, "22", na, na, "33"), last_name = c("b", "b", "b", na, na, "m"), last_name_alyas = c(na, na, na, na, na, "m"), middle_name = c("c", na, na, na, na, na), first_name = c("me", "p", "a", na, na, "s"), first_name_alyas = c(na, na, na, na, na, "f"), maiden_name = c(na, na, "m", na, na, na), id_father = c(2l, 4l, 6l, na, na, 8l), id_mother = c(3l, 5l, 7l, na, na, 9l), birth_date = c("1986-01-01", "1963-01-01", "1964-01-01", na, na, "1936-01-01"), birth_place = c("city", "village", "village", na, na, "village"), death_date = c("0000-00-00", na, na, na, na, "2007-12-23"), death_reason = c(na, na, na, na, na, "stroke"), nr_brothers = c(na, 1l, na, na, na, na), brothers_names = c(na, "m", na, na, na, na), nr_sisters = c(1l, na, 1l, na, na, 2l), sisters_names = c("a", na, "e", na, na, na), school = c(na, "", "", na, na, ""), occupation = c(na, "", "", na, na, ""), diseases = c(na_character_, na_character_, na_character_, na_character_, na_character_, na_character_), comments = c(na_character_, na_character_, na_character_, na_character_, na_character_, na_character_) ), .names = c("id", "cnp", "last_name", "last_name_alyas", "middle_name", "first_name", "first_name_alyas", "maiden_name", "id_father", "id_mother", "birth_date", "birth_place", "death_date", "death_reason", "nr_brothers", "brothers_names", "nr_sisters", "sisters_names", "school", "occupation", "diseases", "comments"), row.names = c(na, 6l), class = "data.frame" )
is there way can plot family tree ggplot? if not, how can plot using package.
the primary key 'id' , connect other members of family using "id_father" , "id_mother".
as noted in comments, should try igraph
. here quick start:
require(igraph) mothers=familytree[,c('id','id_mother','first_name', 'last_name')] fathers=familytree[,c('id','id_father','first_name', 'last_name')] mothers$name=paste(mothers$first_name,mothers$last_name) fathers$name=paste(fathers$first_name,fathers$last_name) names(mothers)=c('parent','id','first_name','last_name','name') names(fathers)=c('parent','id','first_name','last_name','name') links=rbind(mothers,fathers) links=links[!is.na(links$id),] g=graph.data.frame(links) co=layout.reingold.tilford(g, flip.y=f) plot(g,layout=co)
there aren't names, , arrows going in wrong direction, should able go there.
Comments
Post a Comment