I need to make stacked area chart using the echarts4r
. In spite of great examples on javascript I can't find the solution how to make the area chart stacked using R.
Ideally it is also necessary to add to the chart the tooltip with percentage from total as in my example using highcharter
package.
library(echarts4r)
library(highcharter)
set.seed(2018)
dt <- data.frame(a =1:10,
x = rnorm(10, mean = 20, sd = 5),
y = rnorm(10, mean = 20, sd = 5),
z = rnorm(10, mean = 10, sd = 5))
echarts <- dt %>%
e_charts(a) %>%
e_area(x, stack = "stack", origin = 'start') %>%
e_area(y, stack = "stack", origin = 'start') %>%
e_area(z, stack = "stack", origin = 'start') %>%
e_grid(left = '4%', right = '3%', bottom = '10%', containLabel = true) %>%
e_tooltip(trigger = "axis", axisPointer = list(type = 'cross')) %>%
e_toolbox(left = 'right', itemSize = 15, top = 22) %>%
e_toolbox_feature("saveAsImage", title = 'save as image') %>%
e_toolbox_feature("dataZoom", title = list(zoom = "zoom", back = "back")) %>%
e_toolbox_feature("restore", title = 'restore') %>%
e_theme("infographic") %>%
e_legend(type = 'scroll', bottom = 1)
echarts
highchart <- highchart() %>%
hc_xAxis(categories = dt$a) %>%
hc_add_series(data = dt$x, name = 'x') %>%
hc_add_series(data = dt$y, name = 'y') %>%
hc_add_series(data = dt$z, name = 'z') %>%
hc_chart(type = "area") %>%
hc_plotOptions(area = list(stacking = "normal", lineColor = "#ffffff",
lineWidth = 1, marker = list( lineWidth = 1,
lineColor = "#ffffff"))) %>%
hc_legend(reversed = FALSE) %>%
hc_tooltip(crosshairs = TRUE, backgroundColor = "#FCFFC5", shared = TRUE, borderWidth = 5,
pointFormat = "<span style=\"color:{series.color}\">{series.name}</span>:
<b>{point.percentage:.1f}%</b> ({point.y:,.0f} users)<br/>")
highchart