12

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.

3
  • 3
    datamodelr looks like it may do what you want. Commented Feb 27, 2019 at 21:13
  • 1
    The datamodelr package is now the 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). Commented Jul 24, 2021 at 2:43
  • 1
    Look at cran.r-project.org/web/packages/ReDaMoR/vignettes/ReDaMoR.html Commented Aug 3, 2022 at 11:51

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

The OmniGraffle link (both here and in the reference) point to Gliffy. OmniGraffle looks to be a completely separate company/product and only for Mac/iOS.
2

For those (like me) who would search for making entity relational diagram (e.g., for database models), as of now, the features of the datamodelr package are now included in the dm package.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.