Organize graph nodes vertically according to a 'y' value in R / ggraph

93 views Asked by At

I created this little package to organize "family" data with the hope of creating genealogical trees using ggraph/tidygraph. I managed to obtain a graph like this (the data can be loaded without the package - cf. code at the end):

remotes::install_github("DominiqueMakowski/tidyfamily")
library(tidyfamily)
library(ggraph)
library(tidygraph)

data <- dynasty_capetian()

edges <- tidyfamily:::.family_get_edges(data)
nodes <- tidyfamily:::.family_get_nodes(data)


tidygraph::tbl_graph(nodes=nodes, edges=edges) %>%
  ggraph(layout = "nicely") +
  geom_edge_link(aes(color = link)) +
  geom_node_label(aes(label = label)) +
  ggraph::theme_graph()

Created on 2021-04-15 by the reprex package (v0.2.1)

However, the graph is not the clearest visualization, and something that looks more like a tree or dendrogram would be better.

I believe that one of the ways (or at least, a first step) of approaching that would be to organize the nodes according to the birth date of the people (the birth_year is available as property of the nodes).

In other words, I would like to have implicitly a "y" axis in this graph and have the nodes put at their height, depending some of their properties. Is that possible?

Data without installing package

data <- structure(list(id = c("Charles", "Louis XIV", "Louis XV", "Louis1661", 
"Louis1682", "Marie-Adélaïde de Savoie", "Marie-Thérèse d'Autriche", 
"Marie-Thérèse de France", "Marie Anne Christine de Bavière", 
"Philippe-Charles de France", "Philippe V"), name = c("Charles", 
"Louis XIV", "Louis XV", "Louis de France", "Louis de France", 
"Marie-Adélaïde de Savoie", "Marie-Thérèse d'Autriche", "Marie-Thérèse de France", 
"Marie Anne Christine de Bavière", "Philippe-Charles de France", 
"Philippe V d'Espagne"), text = c(NA, NA, NA, NA, "Duc de Bourgogne", 
NA, NA, "La Petite Madame", NA, "Duc d'Anjou", NA), sex = c("Male", 
"Male", "Male", "Male", "Male", "Female", "Female", "Female", 
"Female", "Male", "Male"), birth_year = c(1686, 1638, 1710, 1661, 
1682, 1685, 1638, 1667, 1660, 1668, 1683), birth_month = c(7, 
9, 2, 11, NA, 12, 10, NA, NA, 8, NA), birth_day = c(31L, 5L, 
15L, 1L, NA, 6L, 10L, NA, NA, 5L, NA), birth_text = c("31 Jul 1686", 
"05 Sep 1638", "15 Feb 1710", "01 Nov 1661", "1682", "06 Dec 1685", 
"10 Oct 1638", "1667", "1660", "05 Aug 1668", "1683"), death_year = c(NA, 
1715, 1774, 1711, 1712, 1712, 1683, 1672, NA, 1671, 1746), death_month = c(NA, 
9, 5, 4, NA, 2, 7, NA, NA, 7, NA), death_day = c(NA, 1L, 10L, 
14L, NA, 12L, 30L, NA, NA, 10L, NA), death_text = c("Unknown", 
"01 Sep 1715", "10 May 1774", "14 Apr 1711", "1712", "12 Feb 1712", 
"30 Jul 1683", "1672", "Unknown", "10 Jul 1671", "1746"), father = c("Louis1661", 
NA, "Louis1682", "Louis XIV", "Louis1661", NA, NA, "Louis XIV", 
NA, "Louis XIV", "Louis1661"), mother = c("Marie Anne Christine de Bavière", 
NA, "Marie-Adélaïde de Savoie", "Marie-Thérèse d'Autriche", "Marie Anne Christine de Bavière", 
NA, NA, "Marie-Thérèse d'Autriche", NA, "Marie-Thérèse d'Autriche", 
"Marie Anne Christine de Bavière"), born_of = c("Wedding", "Wedding", 
"Wedding", "Wedding", "Wedding", "Wedding", "Wedding", "Wedding", 
"Wedding", "Wedding", "Wedding")), row.names = c(NA, -11L), class = "data.frame")
1

There are 1 answers

0
David A Stumpf On

A reasonably priced product is GenoPro. It creates appealing family trees from imported gedcom. files. It also can be programmatically addressed as a com-object allowing you to annotate the colors, etc. I've been using it along with VB.NET code. The outputs are their proprietary gno format but it's easy to save as pdf or export in several format. It was developed for genetic counseling, but is nice for genealogy too.