如何使用R包装器包含泡泡图的highcharts motion插件? [英] How to include highcharts motion plugin for bubble plot using R wrapper?

查看:118
本文介绍了如何使用R包装器包含泡泡图的highcharts motion插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Highcharts motion插件 - 需要3次调整才能进入高图。


  1. 包含js资源

  2. 运动的选项对象

  3. 数据位于 sequence 数组中。

对于 Highcharts ,似乎有两个主要的 R 包装器。 Ramnath的 rCharts 和最近发布的CRAN

所以我的问题:是否有可能使用当前可用的包装器随着时间的推移对泡泡图进行动画制作,以及如何进行动画制作?


$ b

rCharts尝试1
从一个气泡图开始,介绍3个必需的动作选项:

  library(rCharts)#highcharts包装hPlot()

#数据
set.seed(1)
df.SO < - data.frame(date = sample(2005:2016,21,replace = T)
,x = rnorm(21,10,4)
,y = rnorm(21,150,4)
,z = rbinom(21,80,8)
,entities = sample(c(entity1,entity2,entity3),21,replace = T))

#chart
h1 < - hPlot(x =x
,y =y
,size =z
,group =entities
,data = df.SO
,type =bubble)

###动态图表插件###
## 1.包含运动js资产头部
h1 $ addAssets(jshead =https://rawgit.com/larsac07/Motion-Highcharts-Plugin/master/motion.js )

## 2.添加运动对象
h1 $ params $ motion< - list(enabled =true,
labels = unique(sort(df.SO $ date)),
loop =true,
series = 1,
updateInterval = 50,
magnet = list(
round =round,
step = 0.1))

## 3.序列数据??死胡同的办法?

查看图表 - 显示气泡和小部件来播放动画,但动画失败
print(h1)



rCharts - 尝试2
按照序列重组数据,然后输入到图表中。



<$ p $
library(data.table)## v> = 1.9.6
test< code>#3.序列数据 - 投射数据,所以实体是系列和时间是唯一的条目。 ; - dcast(setDT(df.SO),date_event,value.var = c(x,y,z))

#chart
h1< ; - highcharts $ new()
h1 $ chart(type =bubble,height = 300)
h1 $ series(
list(name =entity1,
data = list(
sequence = test $ x_length_entity1,
sequence = test $ y_length_entity1,
sequence = test $ z_length_entity1

),
list(name =entity2,
data = list(
sequence = test $ x_length_entity2,
sequence = test $ y_length_entity2,
sequence = test $ z_length_entity2

),replace = T)

## 1.将头部运动js资源包含在
h1 $ addAssets(jshead =https ://rawgit.com/larsac07/Motion-Highcharts-Plugin/master/motion.js)

## 2.添加运动对象
h1 $ params $ motion< - list (enabled =true,
labels = unique(sort(test $ date)),
loop =true,
series = 1,
updateInterval = 50,
magnet = list(
round =round,
step = 0.1))

#查看图表 - 此方法不显示任何气泡
print(h1)


解决方案

Luke,



motion.js 插件已添加到 highcharter 中。在开发版本中(通过 devtools 下载),它需要更多的测试,但这是一个开始。

请检查 http://jkunst.com/highcharter/plugins.html#motion 中的示例:

  highchart()%>%
hc_chart(type =column)%>%
hc_yAxis(max = 6,min = 0)%>%
hc_add_series(name =A,data = c(2,3,4),zIndex = -10)%>%
hc_add_series(name =B,
data = list(
list(sequence = c(1,2,3,4)),
list(sequence = c(3,2 ,1,3)),
list(sequence = c(2,5,4,3))
))%>%
hc_add_series(name =C,
data = list(
list(sequence = c(3,2,1,3)),
list(sequence = c(2,5,4,3)),
列表(sequence = c(1,2,3,4))
))%>%
hc_motion(enabled = TRUE,
labels = 2000:2003,
series = c(1,2))

如果您发现任何怀疑行为(aka bugs),请在此处报告: https://github.com/jbkunst/highcharter/issues



希望它有帮助


Highcharts motion plugin - Requires 3 adjustments to a highchart.

  1. The inclusion of the js asset
  2. An option object for motion
  3. Data to be within sequence arrays.

It seems like there are two main R wrappers for Highcharts. Ramnath's rCharts and the recently released on CRAN highcharter.

So my question: is it possible to animate a bubble highchart over time with the currently available wrappers and if so how?

rCharts Attempt 1 Starting with a bubble chart and introducing the 3 required motion options:

library(rCharts) # highcharts wrapper hPlot()

# data
set.seed(1)
df.SO <- data.frame(date = sample(2005:2016, 21, replace = T)
                    , x = rnorm(21, 10, 4)
                    , y = rnorm(21, 150, 4)
                    , z = rbinom(21, 80, .8)
                    , entities = sample(c("entity1","entity2","entity3"), 21, replace = T))

# chart
h1 <- hPlot(  x     = "x"
              , y     = "y"
              , size  = "z"
              , group = "entities"
              , data  = df.SO
              , type  = "bubble")

### Motion Charts plugin ###
## 1. include motion js asset in head
h1$addAssets(jshead = "https://rawgit.com/larsac07/Motion-Highcharts-Plugin/master/motion.js")

## 2. add motion object
h1$params$motion  <- list(enabled = "true",
                          labels  = unique(sort(df.SO$date)),
                          loop    = "true",
                          series  = 1,
                          updateInterval = 50,
                          magnet  = list(
                              round = "round",
                              step = 0.1))

## 3. sequence data?? Dead end approach??

# view chart - displays bubbles and widget to play animation, but animation fails
print(h1)

rCharts - Attempt 2 Restructure data as sequences then feed into chart.

# 3. sequence data - cast data so entities are series and times are unique entries
library(data.table) ## v >= 1.9.6
test <- dcast(setDT(df.SO), date ~ entities, value.var = c("x", "y", "z"))

# chart
h1 <- Highcharts$new()
h1$chart(type = "bubble", height = 300)
h1$series(
    list(name = "entity1",
        data = list(
            sequence = test$x_length_entity1,
            sequence = test$y_length_entity1,
            sequence = test$z_length_entity1
        )
    ),
    list(name = "entity2",
         data = list(
             sequence = test$x_length_entity2,
             sequence = test$y_length_entity2,
             sequence = test$z_length_entity2
         )
    ), replace = T)

## 1. include motion js asset in head
h1$addAssets(jshead = "https://rawgit.com/larsac07/Motion-Highcharts-Plugin/master/motion.js")

## 2. add motion object
h1$params$motion  <- list(enabled = "true",
                          labels  = unique(sort(test$date)),
                          loop    = "true",
                          series  = 1,
                          updateInterval = 50,
                          magnet  = list(
                              round = "round",
                              step = 0.1))

# view chart - this approach doesn't display any bubbles
print(h1)

解决方案

Luke,

motion.js plugin was added to highcharter. Is in development version (download via devtools), it's need more testing but is it a start.

Please check the example in http://jkunst.com/highcharter/plugins.html#motion:

  highchart() %>% 
    hc_chart(type = "column") %>% 
    hc_yAxis(max = 6, min = 0) %>% 
    hc_add_series(name = "A", data = c(2,3,4), zIndex = -10) %>% 
    hc_add_series(name = "B",
                  data = list(
                    list(sequence = c(1,2,3,4)),
                    list(sequence = c(3,2,1,3)),
                    list(sequence = c(2,5,4,3))
                  )) %>% 
    hc_add_series(name = "C",
                  data = list(
                    list(sequence = c(3,2,1,3)),
                    list(sequence = c(2,5,4,3)),
                    list(sequence = c(1,2,3,4))
                  )) %>% 
    hc_motion(enabled = TRUE,
              labels = 2000:2003,
              series = c(1,2))

If you find any suspicions behavior (aka bugs) please report here: https://github.com/jbkunst/highcharter/issues

Hope it helps

这篇关于如何使用R包装器包含泡泡图的highcharts motion插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆