Learn R Programming

drake (version 5.3.0)

render_sankey_drake_graph: Render a Sankey diagram fromdrake_graph_info().

Description

This function is called inside sankey_drake_graph(), which typical users call more often. A legend is unfortunately unavailable for the graph itself (https://github.com/christophergandrud/networkD3/issues/240) but you can see what all the colors mean with visNetwork::visNetwork(drake::legend_nodes()).

Usage

render_sankey_drake_graph(graph_info, file = character(0),
  selfcontained = FALSE, ...)

Arguments

graph_info

list of data frames generated by drake_graph_info(). There should be 3 data frames: nodes, edges, and legend_nodes.

file

Name of HTML file to save the graph. If NULL or character(0), no file is saved and the graph is rendered and displayed within R.

selfcontained

logical, whether to save the file as a self-contained HTML file (with external resources base64 encoded) or a file with external resources placed in an adjacent directory. If TRUE, pandoc is required.

...

arguments passed to networkD3::sankeyNetwork().

Value

A visNetwork graph.

See Also

sankey_drake_graph(), vis_drake_graph(), static_drake_graph()

Examples

Run this code
# NOT RUN {
test_with_dir("Quarantine side effects.", {
load_mtcars_example() # Get the code with drake_example("mtcars").
# Instead of jumpting right to sankey_drake_graph(), get the data frames
# of nodes, edges, and legend nodes.
config <- drake_config(my_plan) # Internal configuration list
sankey_drake_graph(config) # Jump straight to the interactive graph.
# Show the legend separately.
visNetwork::visNetwork(nodes = drake::legend_nodes())
# Get the node and edge info that sankey_drake_graph() just plotted:
graph <- drake_graph_info(config)
# You can pass the data frames right to render_sankey_drake_graph()
# (as in sankey_drake_graph()) or you can create
# your own custom visNewtork graph.
render_sankey_drake_graph(graph, width = '100%') # Width is passed to visNetwork.
# Optionally visualize clusters.
config$plan$large_data <- grepl("large", config$plan$target)
graph <- drake_graph_info(
  config, group = "large_data", clusters = c(TRUE, FALSE))
render_sankey_drake_graph(graph)
# You can even use clusters given to you for free in the `graph$nodes`
# data frame.
graph <- drake_graph_info(
  config, group = "status", clusters = "imported")
render_sankey_drake_graph(graph)
})
# }

Run the code above in your browser using DataLab