HighCharts Sankey Diagram in R

Multi tool use
HighCharts Sankey Diagram in R
I'd like to create a sankey diagram using the highcharter library in R. Usually I'm just able to look at the javascript code for the plot and translate it for R, but for sankey plots I'm having some trouble. I'd like to just start by creating something like this: http://jsfiddle.net/highcharts/z2rL672w/3/
Here's my attempt so far. I'm having trouble where to place the "keys" argument.
highchart() %>%
hc_chart(type='sankey') %>%
hc_add_series_list(
list(
keys=c('from', 'to', 'weight')
),
list(
data=list(
list(
from='AT',
to='DE',
weight=10
),
list(
from='DE',
to='CH',
weight=5
),
list(
from='DE',
to='FI',
weight=5
)
)
)
)
EDIT:
I'm now trying the following. Still having a bit of trouble
library(highcharter)
library(tidyverse)
library(jsonlite)
dat <- data.frame(from=c('AT', 'DE', 'CH', 'DE'),
to=c('DE', 'CH', 'DE', 'FI'),
weight=c(10, 5, 15, 5)) %>%
toJSON()
highchart() %>%
hc_chart(type='sankey') %>%
hc_series(dat)
keys
{from: 'AT' to: 'DE', weight: 10}
keys
Thank you for the response! I'm still having a little trouble though. Can you check my attempt above?
– Joe Bringley
May 9 at 14:37
I don't know much about R, so I don't know what exactly is going on in your code. Here's a list of supported data formats in Highcharts: highcharts.com/docs/chart-concepts/series Maybe it'll help.
– Kamil Kulig
May 10 at 7:39
1 Answer
1
I used the function hc_add_series
(without keys) and it worked:
hc_add_series
highchart() %>%
hc_chart(type = 'sankey') %>%
hc_add_series(
data = list(
list(from = 'AT', to = 'DE', weight = 10),
list(from = 'DE', to = 'CH', weight = 5),
list(from = 'DE', to = 'FI', weight = 5))
)
library(highcharter)
library(tidyverse)
library(jsonlite)
dat <- data.frame(from = c('AT', 'DE', 'CH', 'DE'),
to = c('DE', 'CH', 'DE', 'FI'),
weight = c(10, 5, 15, 5)) %>%
toJSON()
highchart() %>%
hc_chart(type = 'sankey') %>%
hc_add_series(data = dat)
I hope that could help :)
I use a development version 0.6.0 of highcharter, to install it please use: devtools::install_github("jbkunst/highcharter")
devtools::install_github("jbkunst/highcharter")
Thanks for the response! I'm not getting any errors but not getting any display either :( what version of highcharter are you using?
– Joe Bringley
Jul 5 at 16:58
I have highcharter(0.6.0).
– Ferand Dalatieh
Jul 6 at 9:05
I'm interested in this too. How did you get v0,6? It looks like the current version is 0.5 (CRAN.R-project.org/package=highcharter)
– Paul Govan
Jul 9 at 18:37
It looks like this is a developmental feature. @JoeBringley try downloading the developmental version.
– Paul Govan
Jul 9 at 20:05
Oh ya it is a development version, and you can install it using: devtools::install_github("jbkunst/highcharter")
– Ferand Dalatieh
Jul 10 at 8:31
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You don't need
keys
property if your points are defined as JSONs (e.g.{from: 'AT' to: 'DE', weight: 10}
): jsfiddle.net/BlackLabel/28r99qbj Practical usage ofkeys
property is explained in the API: api.highcharts.com/highcharts/series.sankey.keys– Kamil Kulig
May 9 at 9:16