[英]Waterfall chart on echarts4r?
Hi and thanks for reading me I'm working with a bar chart on R with the Echarts4r package, but I want to do a waterfall chart and I don't find an option to do a plot like the following on the image:嗨,感谢阅读我的文章,我正在使用 Echarts4r 包在 R 上处理条形图,但我想做一个瀑布图,但我没有找到在图像上绘制如下图的选项:
It's possible to do this chart type?可以做这种图表类型吗? The code I'm using for now is the following:
我现在使用的代码如下:
library(echarts4r)
df <- data.frame(
var = sample(LETTERS, 5),
value = rnorm(5, mean = 200, sd = 100)
)
df |>
e_charts(var) |>
e_bar(value)
Not sure whether echarts4r
offers an option out of the box but following with some data wrangling you could achieve your result as a stacked bar chart like so:不确定
echarts4r
是否提供了一个echarts4r
即用的选项,但是通过一些数据整理,您可以将结果作为堆叠条形图实现,如下所示:
Disclaimer: I borrowed the basic idea from here .免责声明:我从这里借用了基本思想。
library(echarts4r)
library(dplyr)
set.seed(42)
df <- data.frame(
var = sample(LETTERS, 5),
value = rnorm(5, mean = 200, sd = 100)
)
df |>
mutate(bottom = cumsum(dplyr::lag(value, default = 0)),
bottom = ifelse(value < 0, bottom + value, bottom),
top = abs(value)) |>
e_charts(var) |>
e_bar(bottom, stack = "var", itemStyle = list(color = "transparent", barBorderColor = "transparent")) |>
e_bar(top, stack = "var")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.