make_sankey | R Documentation |
A Sankey diagram is a flow diagram in which the width of the lines is proportional to the rate of energy flow. Sankey diagrams are a helpful way to visualize energy flows in an energy conversion chain (ECC). This function takes a matrix description of an ECC and produces a Sankey diagram.
make_sankey(
.sutmats = NULL,
R = Recca::psut_cols$R,
U = Recca::psut_cols$U,
V = Recca::psut_cols$V,
Y = Recca::psut_cols$Y,
simplify_edges = TRUE,
colour_string = NULL,
name_col = "name",
colour_col = "colour",
sankey = Recca::sankey_cols$sankey,
...
)
.sutmats |
An optional wide-by-matrices data frame |
R , U , V , Y |
See |
simplify_edges |
A boolean which tells whether edges should be simplified.
Applies to every row of |
colour_string |
An optional Javascript string that defines colours
for the Sankey diagram,
appropriate for use by |
name_col , colour_col |
The names of columns in |
sankey |
See |
... |
Arguments passed to |
At present, this function uses networkD3::sankeyNetwork()
to draw the Sankey diagram.
If any of R
, U
, V
, or Y
is NA
, NA
is returned.
Note that there appears to be a colour bug
in networkD3::sankeyNetwork()
when a node name ends in a ".".
Colours for those nodes does not render correctly.
a Sankey diagram
library(dplyr)
library(magrittr)
library(networkD3)
library(tidyr)
# Default colours are likely to appear nearly random.
UKEnergy2000mats |>
tidyr::pivot_wider(names_from = "matrix.name",
values_from = "matrix") |>
make_sankey() |>
extract2("Sankey") |>
extract2(1)
# Create your own colour palette.
colour_df <- tibble::tribble(~name, ~colour,
"Resources [of Crude]", "gray",
"Crude dist.", "gray",
"Oil fields", "gray",
"Oil refineries", "gray",
"Diesel dist.", "gray",
"Power plants", "gray",
"Elect. grid", "gray",
"Resources [of NG]", "gray",
"NG dist.", "gray",
"Gas wells & proc.", "gray",
"Petrol dist.", "gray",
"Transport", "gray",
"Residential", "gray",
"Waste", "gray",
"Crude", "black",
"Crude [from Dist.]", "black",
"Crude [from Fields]", "black",
"Diesel", "brown",
"Diesel [from Dist.]", "brown",
"Diesel [from Fields]", "brown",
"Elect", "yellow",
"Elect [from Grid]", "yellow",
"NG", "lightblue",
"NG [from Dist.]", "lightblue",
"NG [from Wells]", "lightblue",
"Petrol", "orange",
"Petrol [from Dist.]", "orange")
colour_df
UKEnergy2000mats |>
tidyr::pivot_wider(names_from = "matrix.name",
values_from = "matrix") |>
make_sankey(colour_string = colour_df,
# Arguments are passed to networkD3::sankeyNetwork()
fontSize = 10,
fontFamily = "Helvetica",
units = "ktoe",
width = 400, # pixels
height = 400 # pixels
) |>
extract2("Sankey") |>
extract2(1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.