10

Does anyone know of a simple and easy method for creating entity relation diagrams (ERD) in R besides graphviz and/or DiagrammeR. I don't use graphviz much and often take more time than I'd like remembering it's syntax just to create a simple figure.

I'd like to create something similar to what Hadley Wickham has in his "R for Data Science" on the chapter about Relational Data. The specific figure can be seen here.

Note: I don't know if this figure was actually done in R or not. I just like the layout and would like to be able to easily reproduce something like this in R.

Phil
  • 7,287
  • 3
  • 36
  • 66
code_cowboy
  • 596
  • 5
  • 18
  • 3
    [datamodelr](https://github.com/bergant/datamodelr) looks like it may do what you want. – neilfws Feb 27 '19 at 21:13
  • 1
    The datamodelr package is now the [dm](https://cynkra.github.io/dm/) package. Note that its function for making ERD diagrams is built on DiagrammeR but the syntax is very simple (so if it's a syntax issue you have with DiagrammeR this should help, but if it's appearance/something else it might not). – userLL Jul 24 '21 at 02:43
  • 1
    Look at https://cran.r-project.org/web/packages/ReDaMoR/vignettes/ReDaMoR.html – Indranil Gayen Aug 03 '22 at 11:51

1 Answers1

1

Yes, Jeffrey B. Arnold has explained this in his book R for Data Science: Exercise Solutions. Please find the excerpt from exercise 13.3.3, chapter 13 below:

1. OmniGraffle (default, what you see from the R4DS book)

R for Data Science uses database schema diagrams to illustrate relations between the tables. Most flowchart or diagramming software can be used used to create database schema diagrams, as well as some specialized database software. The diagrams in R for Data Science were created with OmniGraffle, and their sources can be found in its GitHub repository.

2. datamodelr package in R

Another option to draw database schema diagrams is the R package datamodelr, which can programmatically create database schema diagrams. The following code uses datamodelr to draw a diagram of the relations between the Batting, Master, and Salaries tables.

library(datamodelr)

dm1 <- dm_from_data_frames(list(
  Batting = Lahman::Batting,
  Master = Lahman::Master,
  Salaries = Lahman::Salaries
)) %>%
  dm_set_key("Batting", c("playerID", "yearID", "stint")) %>%
  dm_set_key("Master", "playerID") %>%
  dm_set_key("Salaries", c("yearID", "teamID", "playerID")) %>%
  dm_add_references(
    Batting$playerID == Master$playerID,
    Salaries$playerID == Master$playerID
  )

dm_create_graph(dm1, rankdir = "LR", columnArrows = TRUE) %>%
  dm_render_graph()

You will see:

enter image description here

Reference: https://jrnold.github.io/r4ds-exercise-solutions/relational-data.html#exercise-13.3.3

Grasshopper_NZ
  • 302
  • 1
  • 10