Packages & Warnings :/
library("igraph") # convex_hull
##
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
## The following object is masked from 'package:base':
##
## union
library("viridisLite") # colors
## Warning: package 'viridisLite' was built under R version 3.2.4
library("highcharter")
##
## Attaching package: 'highcharter'
## The following object is masked from 'package:igraph':
##
## %>%
library("purrr")
## Warning: package 'purrr' was built under R version 3.2.3
##
## Attaching package: 'purrr'
## The following objects are masked from 'package:igraph':
##
## %>%, compose, simplify
library("purrr")
library("dplyr")
##
## Attaching package: 'dplyr'
## The following object is masked from 'package:purrr':
##
## order_by
## The following objects are masked from 'package:igraph':
##
## %>%, as_data_frame, groups, union
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Ex 1
ds <- map(seq(5), function(x){
list(data = cummean(rnorm(100, 2, 5)), name = x)
})
highchart() %>%
hc_plotOptions(series = list(marker = list(enabled = FALSE))) %>%
hc_add_series_list(ds)
Ex 2
n <- 3
set.seed(100)
ds2 <- map(seq(n), function(x){
xc <- round(rnorm(1, sd = 2), 2)
yc <- round(rnorm(1, sd = 2), 2)
dt <- cbind(rnorm(200, xc), rnorm(200, yc))
dt <- convex_hull(dt)
dt <- list.parse2(as.data.frame(dt$rescoords))
list(data = dt, name = sprintf("%s, %s", xc, yc), type = "polygon", id = n)
})
set.seed(100)
ds3 <- map(seq(n), function(x){
xc <- round(rnorm(1, sd = 2), 2)
yc <- round(rnorm(1, sd = 2), 2)
dt <- cbind(rnorm(200, xc), rnorm(200, yc))
dt <- list.parse2(as.data.frame(dt))
list(data = dt, name = sprintf("%s, %s", xc, yc), type = "scatter", linkedTo = n)
})
cols <- hex_to_rgba(substr(viridis(n), 0, 7), alpha = 0.5)
highchart() %>%
hc_colors(colors = cols) %>%
hc_add_series_list(ds2) %>%
hc_add_series_list(ds3)
Ex 3
data("economics_long", package = "ggplot2")
head(economics_long)
## Source: local data frame [6 x 4]
## Groups: variable [1]
##
## date variable value value01
## (date) (fctr) (dbl) (dbl)
## 1 1967-07-01 pce 507.4 0.0000000000
## 2 1967-08-01 pce 510.5 0.0002660008
## 3 1967-09-01 pce 516.3 0.0007636797
## 4 1967-10-01 pce 512.9 0.0004719369
## 5 1967-11-01 pce 518.1 0.0009181318
## 6 1967-12-01 pce 525.8 0.0015788435
ds <- economics_long %>%
group_by(variable) %>%
do(ds = list(
data = list.parse2(data.frame(datetime_to_timestamp(.$date), .$value01))
)) %>%
{map2(.$variable, .$ds, function(x, y){
append(list(name = x), y)
})}
highchart() %>%
hc_xAxis(type = "datetime") %>%
hc_add_series_list(ds)