dm_draw() uses DiagrammeR to draw diagrams.

dm_set_colors() allows to define the colors that will be used to display the tables of the data model. The colors can either be either specified with hex color codes or using the names of the built-in R colors. An overview of the colors corresponding to the standard color names can be found at the bottom of http://rpubs.com/krlmlr/colors.

dm_get_colors() returns the colors defined for a data model.

dm_get_available_colors() returns an overview of the names of the available colors These are the standard colors also returned by grDevices::colors() plus a default table color with the name "default".

dm_draw(
  dm,
  rankdir = "LR",
  col_attr = "column",
  view_type = "keys_only",
  columnArrows = TRUE,
  graph_attrs = "",
  node_attrs = "",
  edge_attrs = "",
  focus = NULL,
  graph_name = "Data Model"
)

dm_set_colors(dm, ...)

dm_get_colors(dm)

dm_get_available_colors()

Arguments

dm

A dm object.

rankdir

Graph attribute for direction (e.g., 'BT' = bottom --> top).

col_attr

Column atributes to display. By default only the column name ("column") is displayed.

view_type

Can be "keys_only" (default), "all" or "title_only". It defines the level of details for rendering tables (only primary and foreign keys, all columns, or no columns).

columnArrows

Edges from columns to columns (default: TRUE).

graph_attrs

Additional graph attributes.

node_attrs

Additional node attributes.

edge_attrs

Additional edge attributes.

focus

A list of parameters for rendering (table filter).

graph_name

The name of the graph.

...

Colors to set in the form color = table. Allowed colors are all hex coded colors (quoted) and the color names from dm_get_available_colors(). tidyselect is supported, see dplyr::select() for details on the semantics.

Value

For dm_draw(): returns an object of class grViz (see also DiagrammeR::grViz()), which, when printed, produces the output seen in the viewer as a side effect.

For dm_set_colors(): the updated data model.

For dm_get_colors(), a two-column tibble with one row per table.

For dm_get_available_colors(), a vector with the available colors.

Examples

dm_nycflights13() %>% dm_draw()
%0 airlines airlines carrier airports airports faa flights flights carrier tailnum origin flights:carrier->airlines:carrier flights:origin->airports:faa planes planes tailnum flights:tailnum->planes:tailnum weather weather
dm_nycflights13(cycle = TRUE) %>% dm_draw(view_type = "title_only")
%0 airlines airlines airports airports flights flights flights:carrier->airlines:carrier flights:origin->airports:faa flights:dest->airports:faa planes planes flights:tailnum->planes:tailnum weather weather
head(dm_get_available_colors())
#> [1] "default" "white" "aliceblue" "antiquewhite" #> [5] "antiquewhite1" "antiquewhite2"
length(dm_get_available_colors())
#> [1] 658
dm_nycflights13() %>% dm_get_colors()
#> #ED7D31FF #ED7D31FF #5B9BD5FF #ED7D31FF #70AD47FF #> "airlines" "airports" "flights" "planes" "weather"
dm_nycflights13(color = FALSE) %>% dm_set_colors( darkblue = starts_with("air"), "#5986C4" = flights ) %>% dm_draw()
%0 airlines airlines carrier airports airports faa flights flights carrier tailnum origin flights:carrier->airlines:carrier flights:origin->airports:faa planes planes tailnum flights:tailnum->planes:tailnum weather weather
# Splicing is supported: nyc_cols <- dm_nycflights13() %>% dm_get_colors() nyc_cols
#> #ED7D31FF #ED7D31FF #5B9BD5FF #ED7D31FF #70AD47FF #> "airlines" "airports" "flights" "planes" "weather"
dm_nycflights13(color = FALSE) %>% dm_set_colors(!!!nyc_cols) %>% dm_draw()
%0 airlines airlines carrier airports airports faa flights flights carrier tailnum origin flights:carrier->airlines:carrier flights:origin->airports:faa planes planes tailnum flights:tailnum->planes:tailnum weather weather