visNetwork icon indicating copy to clipboard operation
visNetwork copied to clipboard

can I use visNetwork to create family tree?

Open KHBHH opened this issue 5 years ago • 2 comments

I want to create a family tree using visNetwork package.

I am trying to create a family tree using visNetwork package. I have tried using rpart object within visTree,but I do not know how to include data so that family tree appears. Is it possible to obtain family tree (such as pedigree) using rpart and visTree.

I have read about visTree from the following link: https://cran.r-project.org/web/packages/visNetwork/vignettes/Introduction-to-visNetwork.html

I would like my family tree to appear in such way (like the first plot that appears in the above link), but the above example shows how to create regression/classification tree.

KHBHH avatar Jun 12 '19 14:06 KHBHH

Yes it's certainly possible. I have some sample code in my repository here.

This gives a layout of 3 nodes on one level: mother -> marriage <- father Then the children of that marriage are linked to the marriage node and appear on the level below

sheepworrier avatar Jul 04 '19 07:07 sheepworrier

Hey @sheepworrier I think I might be about to do this for my family (if I can rope my uncle into creating the data!). I have several ideas and wanted to look at what you had, but can't reproduce your work w/out the family-tree/Relationships-Table 1.csv. Did you leave that out of the repo intentionally?

Anyway, looking at your code I see you already had the idea of using pictures of the people, and I like your usage of the hover to provide metadata on the individual... I did have those two ideas. I also like how you create a marriage node out of two people to create children from that. Smart! Didn't think of that.

The one idea I had that you haven't implemented is the usage of levels to ensure hierarchy is maintained. Levels could be just numeric 1,2,3, or could be years (as in birthyears) normalized to your range. So if your first person was born in 1900 and your last person was born in 2000, then you would have 100 levels, and each node would get a level 1:100 corresponding to their normalized birth-year. See what I mean? Then you could use this, from here:

It’s also possible to define the level of each node :

nodes <- data.frame(id = 1:4, level = c(2, 1, 1, 1))
edges <- data.frame(from = c(1, 1, 1),
 to = c(2,3,4))
### with level
visNetwork(nodes, edges, width = "100%") %>% 
  visEdges(arrows = "from") %>% 
  visHierarchicalLayout() # same as   visLayout(hierarchical = TRUE)

What do you think? Let me know if you'd like to discuss more privately... seems all three of us are after similar stuff.

DataStrategist avatar Aug 04 '21 17:08 DataStrategist