Highcharter Sankey

时间:2018-04-25 16:01:34

标签: r r-highcharter

我正在尝试使用以下数据框和代码创建一个sankey图:

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专栏:

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

此示例已从此处复制:https://github.com/jbkunst/highcharter/blob/master/dev/highcharts-v6.R

出于某种原因,每当我运行时,绘图屏幕仍为白色,并且没有任何正在绘制的内容。

我在R Studio版本1.1.423(R版本:4.3)

上尝试此操作

有人知道为什么会这样吗?

1 个答案:

答案 0 :(得分:1)

我有同样的问题。首先,我收到了JavaScript控制台错误:

a is undefined

我没有在ui.R中使用正确的函数highchartOutput(),所以我在javascript控制台中找到了它:

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

我发现this post,并有一条评论建议通过以下方式安装highcharter的开发版本:

devtools::install_github("jbkunst/highcharter") 

然后使用该帖子中的简单代码为我解决了这个问题:

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

我能够从那里开始工作。似乎要制作Sankey图表,必须使用开发版本。