Learn R Programming

rock (version 0.9.6)

apply_graph_theme: Apply multiple DiagrammeR global graph attributes

Description

Apply multiple DiagrammeR global graph attributes

Usage

apply_graph_theme(graph, ...)

Value

The DiagrammeR::DiagrammeR graph.

Arguments

graph

The DiagrammeR::DiagrammeR graph to apply the attributes to.

...

One or more character vectors of length three, where the first element is the attribute, the second the value, and the third, the attribute type (graph, node, or edge).

Examples

Run this code
### Create an example source
exampleSource <- '
---
codes:
  -
    id: parentCode
    label: Parent code
    children:
      -
        id: childCode1
      -
        id: childCode2
  -
    id: childCode3
    label: Child Code
    parentId: parentCode
    children: [grandChild1, grandChild2]
---
';

### Parse it
parsedSource <-
  rock::parse_source(
    text = exampleSource
  );

### Extract the deductive code tree from
### the parsed source
deductiveCodeTree <-
  parsedSource$deductiveCodeTrees;

### Convert it to a DiagrammeR graph
miniGraph <-
  data.tree::ToDiagrammeRGraph(
    deductiveCodeTree
  );

### Show the graph
DiagrammeR::render_graph(
  miniGraph
);

### Apply a "theme" (three attributes)
miniGraph_themed <-
  rock::apply_graph_theme(
    miniGraph,
    c("rankdir", "TB", "graph"),
    c("shape", "square", "node"),
    c("style", "solid", "node"),
    c("fontname", "Arial", "node"),
    c("fontcolor", "#0000BB", "node"),
    c("color", "#BB0000", "node")
  );

### Show the updated graph
DiagrammeR::render_graph(
  miniGraph_themed
);

Run the code above in your browser using DataLab