0

I am trying to create a sankey diagram using the following data frame and code:

UKvisits <- data.frame(origin=as.character(c(
  "France", "Germany", "USA",
  "Irish Republic", "Netherlands",
  "Spain", "Italy", "Poland",
  "Belgium", "Australia", 
  "Other countries", rep("UK", 5))),
 visit=as.character(c(
   rep("UK", 11), "Scotland",
  "Wales", "Northern Ireland", 
  "England", "London")),
 weights=c(
  c(12,10,9,8,6,6,5,4,4,3,33)/100*31.8, 
  c(2.2,0.9,0.4,12.8,15.5)))

Highcharter line:

hchart(UKvisits, "sankey", hcaes(from = origin, to = visit, weight = weights))

This example has been copied from here: https://github.com/jbkunst/highcharter/blob/master/dev/highcharts-v6.R

For some reason whenever I run this, the plot screen remains white and nothing is being plotted.

I am trying this on R Studio version 1.1.423 (R Version: 4.3)

Does anybody have any idea why this is happening?

gabzo
  • 198
  • 1
  • 13
  • Doesnt seem to be an RStudio issue, even when using the R console it doesn't seem to plot anything. However, I would change the second code block from `hchart(data, ...)` to `hchart(UKvisits)`, because that's what your data frame is named – onlyphantom Apr 25 '18 at 16:21
  • I've found the `highcharter` library to be difficult to work with outside of the core functionality that has been implemented via the `hchart` function. While it probably is possible to dig into the `highcharter` documentation, and figure out how to make this sankey work in R, you might be better off using another library, or writing the code in Javascript, since you can directly reference the Highcharts documentation – Mako212 Apr 25 '18 at 16:27
  • Sorry there was a typo when I've wrote the ```hchart(data, ...)``` The problem is still persistent @onlyphantom @Mako212 I have tried using the highcharter function and that has the same result. – gabzo Apr 25 '18 at 16:34
  • Maybe consider the `networkD3` library? It seems like there's better documentation on how to create a sankey: https://christophergandrud.github.io/networkD3/#sankey – Mako212 Apr 25 '18 at 16:37
  • 1
    @Mako212 you're right. I think the best choice for me at the moment is using googlevis package -> https://cran.r-project.org/web/packages/googleVis/vignettes/googleVis_examples.html – gabzo Apr 26 '18 at 08:25
  • I copied your code and it worked perfectly with me. – Ferand Dalatieh Jul 03 '18 at 07:30
  • @FerandDalatieh interesting. Mine still doesn't work. It displays just an empty page without any graphs. Any change you can tell me your R studio and R version. Thank you – gabzo Jul 09 '18 at 07:28
  • @GabrielOana I have R version 3.4.4; RStudio version 1.1.383 and the package highcharter version 0.6.0 – Ferand Dalatieh Jul 09 '18 at 09:13

1 Answers1

1

I had this same issue. First I got the javascript console error:

a is undefined

I wasn't using the correct function highchartOutput() in ui.R, then I got this in the javascript console:

Highcharts Error #17 The requested series type does not exist...

I found this post and a comment suggested installing the dev version of highcharter via:

devtools::install_github("jbkunst/highcharter") 

And that fixed the issue for me, using the simple code from that post:

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))
      )

And I was able to work from there. Seems like you must use the dev version if you want to do a Sankey chart.

  • That worked indeed. There were some issues where I had to reinstall some packages but it worked perfectly. Thank you for bringing this up :) – gabzo Jul 12 '18 at 14:38