Skip to contents

Returns a list of ggplot2 layers in draw order, ready to add to a ggplot() call (or combined with dag_theme() by ggplot_dag()).

Usage

dag_layers(
  layout,
  node_color = NULL,
  edge_color = "source",
  palette = metro_palette,
  node_shape = NULL,
  shapes = targets_node_shapes(),
  node_size = NULL,
  edge_width = NULL,
  zoom = 1
)

Arguments

layout

A dag_layout, as returned by dag_layout().

node_color, palette, edge_color

Color resolution arguments: see the pkgdown site's Colors article for the full set of rules and examples. palette must supply at least one color per node (or per distinct value of a node_color column); colors are never recycled, and the default metro_palette() never repeats one. palette = NULL is the same as the default, metro_palette().

node_shape

The shape of a node: NULL (the default), a node column name, or a single shape name. A shape is "circle", "square", "diamond", "triangle" or "triangle_down". NULL follows the nodes' type column if they have one (as a pipeline from tar_dag() does), and otherwise draws circles; a type value that shapes doesn't name is a circle. A column name maps that column to shapes and warns about values shapes doesn't name; a shape name draws every node as that shape. A legend names the shapes whenever more than one is drawn; with node_color set to the same column, it is merged with the color legend. Remove it with + ggplot2::guides(shape = "none").

shapes

Which shape each value of the node_shape column gets: a named character vector (value -> shape), or an unnamed one of shapes assigned to the distinct values in order, which must supply at least one per value. Defaults to targets_node_shapes().

node_size

The size of a node: NULL (the default, every node has the radius node_radius), or the name of a numeric node column, such as the n that dag_collapse() adds (or seconds or bytes of a pipeline from tar_dag()). The radius follows the square root of the value's position between the smallest and the largest value, over the node_size_range of style_metro(), so that it is about the node's area that grows in step with the value. A node with an NA value has the radius node_radius. There is no legend for the size: for a collapsed graph, the labels carry the count. The largest radius a circle may have keeps it inside the grid, but a triangle or diamond reaches further (see node_radius of style_metro()), so with a node_shape of those, the biggest ones in the first or last row, or the left column, may be cut off: raise scale. Two of the biggest nodes in neighboring rows leave almost no room for the line between them: see node_size_range of style_metro().

edge_width

The width of an edge: NULL (the default, every edge is edge_stroke_width wide), or the name of a numeric column of the dag's edges, such as the n of dag_collapse(). The width grows linearly with the value, over the edge_width_range of style_metro(). An edge with an NA value is edge_stroke_width. In this metro layout the edges from one node share a line, and so do those entering one node from the same side, so a shared line is as wide as the widest edge it carries. Each edge is then drawn whole (as for any edge_color but "source"), the widest first, so that the narrower ones stay visible on top; and each bridge is wide enough for the widest edge drawn over it.

zoom

Multiplier for node size, line widths and text size, to match a panel sized at zoom px per data unit (see ggplot_dag()).

Value

A list of ggplot2 layers.

Examples

dag <- as_dag(data.frame(from = c("a", "a", "b"), to = c("b", "c", "c")))
lay <- dag_layout(dag, style_metro())
ggplot2::ggplot() + dag_layers(lay) + dag_theme()