| gvisSankey {googleVis} | R Documentation |
Google Sankey Chart with R
Description
A sankey diagram is a visualization used to depict a flow from one set of values to another. The things being connected are called nodes and the connections are called links. They're named after Captain Sankey, who created a diagram of steam engine efficiency that used arrows having widths proportional to heat loss.
Usage
gvisSankey(data, from = "", to = "", weight = "", options = list(), chartid)
Arguments
data |
data.frame that contains the data to be visualised |
from |
a string that refers to the column name in
|
to |
a string that refers to the column name in
|
weight |
name of the column with the numerical weight of the connections |
options |
list of configuration options. The options are documented in detail by Google online: https://developers.google.com/chart/interactive/docs/gallery/sankey#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
Value
gvisSankey returns list
of class
"gvis" and "list".
An object of class "gvis" is a list containing at least the
following components:
typeGoogle visualisation type
chartidcharacter id of the chart object. Unique chart ids are required to place several charts on the same page.
htmla list with the building blocks for a page
headera character string of a html page header:
<html>...<body>,charta named character vector of the chart's building blocks:
jsHeaderOpening
<script>tag and reference to Google's JavaScript library.jsDataJavaScript function defining the input
dataas a JSON object.jsDrawChartJavaScript function combing the data with the visualisation API and user options.
jsDisplayChartJavaScript function calling the handler to display the chart.
jsFooterEnd tag
</script>.jsChartCall of the
jsDisplayChartfunction.divChart<div>container to embed the chart into the page.
captioncharacter string of a standard caption, including data name and chart id.
footercharacter string of a html page footer:
</body>...</html>, including the used R and googleVis version and link to Google's Terms of Use.
Warning
The sankey chart may be undergoing substantial revisions in future Google Charts releases.
Author(s)
Markus Gesmann markus.gesmann@gmail.com
References
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/sankey
Examples
dat <- data.frame(From=c(rep("A",3), rep("B", 3)),
To=c(rep(c("X", "Y", "Z"),2)),
Weight=c(5,7,6,2,9,4))
sk1 <- gvisSankey(dat, from="From", to="To", weight="Weight")
plot(sk1)
sk2 <- gvisSankey(dat, from="From", to="To", weight="Weight",
options=list(sankey="{link: {color: { fill: '#d799ae' } },
node: { color: { fill: '#a61d4c' },
label: { color: '#871b47' } }}"))
plot(sk2)