R中的HighCharts Sankey图

编程入门 行业动态 更新时间:2024-10-10 03:31:54
本文介绍了R中的HighCharts Sankey图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用R中的highcharter库创建一个sankey图.通常,我只能查看该图的javascript代码并将其转换为R,但是对于sankey图,我遇到了一些麻烦.我想从创建这样的东西开始: jsfiddle/highcharts/z2rL672w/3/

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: jsfiddle/highcharts/z2rL672w/3/

到目前为止,这是我的尝试.我在哪里放置"keys"参数时遇到了麻烦.

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

我现在正在尝试以下方法.仍然有麻烦

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)

推荐答案

我使用了功能hc_add_series(不带键),并且有效:

I used the function hc_add_series (without keys) and it worked:

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)

我希望可以帮到忙:)

我使用highcharter的开发版本0.6.0,要安装它,请使用:devtools::install_github("jbkunst/highcharter")

I use a development version 0.6.0 of highcharter, to install it please use: devtools::install_github("jbkunst/highcharter")

更多推荐

R中的HighCharts Sankey图

本文发布于:2023-07-18 14:22:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1145667.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:HighCharts   Sankey

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!