【问题标题】:Two pies in the same graph - Highcharter同一张图中的两个馅饼 - Highcharter
【发布时间】:2021-02-04 13:38:19
【问题描述】:

我试图在同一个高图中复制两个饼图的following example,但没有成功。下面的示例代码。有谁知道如何在highcharter的同一个图表中创建两个图表?

df = tibble(name = c("a","b","c"),
        a1 = c(10,12,11),
        a2 = c(22,23,22))
highchart() %>%
hc_chart(renderTo = "container", type = "pie") %>%
hc_add_series(df, hcaes(name, a1), size = 100, center = c(30,10)) %>%
hc_add_series(df, hcaes(name, a2), size = 100, center = c(10,30)) 

【问题讨论】:

  • 饼图不是最适合可视化的,例如 Steph Few piecharts。除非您只有 2 个类别并且在 25% 或 50% 左右进行一些比较,否则条形图将更具可读性。

标签: r r-highcharter


【解决方案1】:

一个可能的解决方案

highcharter::hw_grid(
  hchart(df, type = "pie", mapping = hcaes(name, a1))
  ,
  hchart(df, type = "pie", mapping = hcaes(name, a2))
) %>% htmltools::browsable()

【讨论】:

    【解决方案2】:

    我最初认为它应该由center 参数控制,根据您上面的代码(并没有像您指出的那样工作)。

    一种解决方法是:

    highchart() %>% 
    hc_add_series(type = "pie", data = df, hcaes(name, a1),size = 100, name = "test1", center = c(0, 0)) %>%
    hc_add_series(type = "pie", data = df, hcaes(name, a2),size = 100, name = "test2") %>%
    hc_plotOptions(pie = list(center = c(700,450)))
    

    您需要第一个系列中的 center 参数,尽管它除了修复第一个饼图之外没有任何作用(更改 c(0, 0) 实际上并不会改变饼图的位置) 然后使用hc_plotOptions控制第二个饼图的位置。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-21
    • 1970-01-01
    • 1970-01-01
    • 2012-07-25
    相关资源
    最近更新 更多