library(highcharter)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(tidyverse)
## ── Attaching packages
## ────────────────────────────────── tidyverse
## 1.3.2.9000 ──
## ✔ ggplot2 3.3.6 ✔ dplyr 1.0.10
## ✔ tibble 3.1.8 ✔ stringr 1.4.1
## ✔ tidyr 1.2.1 ✔ forcats 0.5.2
## ✔ readr 2.1.3 ✔ lubridate 1.8.0
## ✔ purrr 0.3.5
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
dtrees <- tibble(
tree = c("A", "B"),
apples = c(5, 7)
)
dtrees
## # A tibble: 2 × 2
## tree apples
## <chr> <dbl>
## 1 A 5
## 2 B 7
hchart(dtrees, "column", hcaes(tree, apples), name = "Apples")
dflowers <- tibble(
tree = c(rep("A", 3), rep("B", 4)),
rose = c("R1", "R2", "R3", "R4", "R5", "R6", "R7"),
petals = c(10, 13, 15, 20, 24, 26, 27)
)
dflowers
## # A tibble: 7 × 3
## tree rose petals
## <chr> <chr> <dbl>
## 1 A R1 10
## 2 A R2 13
## 3 A R3 15
## 4 B R4 20
## 5 B R5 24
## 6 B R6 26
## 7 B R7 27
dflowers_dd <- dflowers |>
group_nest(id = tree) |>
mutate(
type = "column",
data = map(data, mutate, name = rose, y = petals),
data = map(data, list_parse),
name = "Petals"
)
dflowers_dd$data[[1]] |> map_df(as_tibble)
## # A tibble: 3 × 5
## tree rose petals name y
## <chr> <chr> <dbl> <chr> <dbl>
## 1 A R1 10 R1 10
## 2 A R2 13 R2 13
## 3 A R3 15 R3 15
dflowers_dd
## # A tibble: 2 × 4
## id data type name
## <chr> <list> <chr> <chr>
## 1 A <list [3]> column Petals
## 2 B <list [4]> column Petals
hchart(
dtrees,
"column",
hcaes(tree, apples, drilldown = tree),
name = "Apples",
colorByPoint = TRUE
) |>
hc_drilldown(
allowPointDrilldown = TRUE,
series = list_parse(dflowers_dd)
) |>
hc_yAxis(title = list(text = "")) |>
hc_xAxis(title = list(text = ""))