highcharts 如何创建一个深入到另一个饼图的piechart?

iyr7buue  于 2022-11-10  发布在  Highcharts
关注(0)|答案(1)|浏览(193)

我看到的例子是条形图深入到条形图,但我似乎找不到一个饼图的例子,深入到另一个饼图在RShiny。

lokaqttq

lokaqttq1#

您可以在hc_drilldown()中指定type参数,如图所示,方法是编辑highcharter reference page中的范例。

library(highcharter)
library(dplyr)
library(purrr)

df <- tibble(
    name = c("Animals", "Fruits"),
    y = c(5, 2),
    drilldown = tolower(name)
)

df

# > # A tibble: 2 x 3

# >   name        y drilldown

# >   <chr>   <dbl> <chr>

# > 1 Animals     5 animals

# > 2 Fruits      2 fruits

hc <- highchart() %>%
    hc_title(text = "Basic drilldown") %>%
    hc_xAxis(type = "category") %>%
    hc_legend(enabled = FALSE) %>%
    hc_plotOptions(
        series = list(
            boderWidth = 0,
            dataLabels = list(enabled = TRUE)
        )
    ) %>%
    hc_add_series(
        data = df,
        type = "pie",
        hcaes(name = name, y = y),
        name = "Things",
        colorByPoint = TRUE
    )

dfan <- data.frame(
    name = c("Cats", "Dogs", "Cows", "Sheep", "Pigs"),
    value = c(4, 3, 1, 2, 1)
)

dffru <- data.frame(
    name = c("Apple", "Organes"),
    value = c(4, 2)
)

dsan <- list_parse2(dfan)

dsfru <- list_parse2(dffru)

hc <- hc %>%
    hc_drilldown(
        allowPointDrilldown = TRUE,
        series = list(
            list(
                id = "animals",
                type = "pie",
                data = dsan
            ),
            list(
                id = "fruits",
                type = "pie",
                data = dsfru
            )
        )
    )
print(hc)

相关问题