I am trying to reproduce the following example of two pies in the same highchart graph with no success. An example code below. Does any one knows how to create two charts in the same chart in 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))
A possible solution
highcharter::hw_grid(
hchart(df, type = "pie", mapping = hcaes(name, a1))
,
hchart(df, type = "pie", mapping = hcaes(name, a2))
) %>% htmltools::browsable()

I initially thought it should be controlled by the center arguments as per your code above (and didn't work as you pointed out).
One workaround is:
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)))
You need the center argument in the first series although it doesn't do anything other than fixing the first pie (changing c(0, 0) doesn't actually change the location of the pie)
then using hc_plotOptions to control the location of the second pie chart.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With