This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
library(highcharter)
## Warning: package 'highcharter' was built under R version 4.0.3
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(purrr)
years <- 10
nx <- 5
ny <- 6
df <- data_frame(year = rep(c(2016 + 1:years - 1), each = nx * ny), xVar = rep(1:nx,
times = years * ny), yVar = rep(1:ny, times = years * nx))
## Warning: `data_frame()` is deprecated as of tibble 1.1.0.
## Please use `tibble()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
df <- df %>% group_by(xVar, yVar) %>% mutate(heatVar = cumsum(rnorm(length(year))))
df_start <- df %>% arrange(year) %>% distinct(xVar, yVar, .keep_all = TRUE)
df_start
df_seqc <- df %>% group_by(xVar, yVar) %>% do(sequence = list_parse(select(.,
value = heatVar)))
df_seqc
data <- left_join(df_start, df_seqc)
## Joining, by = c("xVar", "yVar")
#> Joining, by = c("xVar", "yVar")
data
limits <- (unlist(data$sequence)) %>% {
c(min(.), max(.))
}
limits
## [1] -7.906364 7.168321
hc1 <- hchart(data, type = "heatmap", hcaes(x = xVar, y = yVar, value = heatVar))
hc2 <- hchart(data, type = "heatmap", hcaes(x = xVar, y = yVar, value = heatVar)) %>%
hc_motion(enabled = TRUE, series = 0, startIndex = 0, labels = unique(df$year)) %>%
hc_legend(layout = "vertical", verticalAlign = "top", align = "right") %>%
hc_colorAxis(min = limits[1], max = limits[2])
hc2