【发布时间】:2016-06-29 00:01:06
【问题描述】:
Highcharts motion plugin - Requires 3 adjustments 到高位图。
- 包含 js 资产
-
motion的选项对象 - 数据位于
sequence数组中。
Highcharts 似乎有两个主要的 R 包装器。 Ramnath 的 rCharts 和最近在 CRAN 上发布的 highcharter。
所以我的问题是:是否可以使用当前可用的包装器随着时间的推移为气泡图制作动画,如果可以,如何制作?
rCharts 尝试 1 从气泡图开始并介绍 3 个必需的运动选项:
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 - 尝试 2 将数据重组为序列,然后输入图表。
# 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-singham,我会看看如何在highcharter中实现这个功能,如果成功我会告诉你的。
-
@jbkunst 太棒了,谢谢!这可能会有所帮助:motion.js 使用处理数字、数组和对象的
update.point。建议运动气泡图所需的多元数据是可能的。
标签: javascript r highcharts rcharts