被堆积的水平的瀑布图

时间:2017-10-23 22:52:32

标签: r ggplot2 stacked-chart waterfall

哪些包更适合制作堆叠的水平瀑布图? 像这样的图表:

enter image description here

该图的数据由

给出
x <- data.frame(time = c(rep("this month",3),rep("last month",3)),class = rep(c("Part A","Part B", "Part C"),2),value = c(40,30,45,2,10,-5))

1 个答案:

答案 0 :(得分:3)

一个简单的谷歌搜索显示有几种方法可以实现它  1. GGPLOT2(http://vita.had.co.nz/papers/ggplot2-wires.pdf)(第3页)
 瀑布包。 (https://cran.r-project.org/web/packages/waterfall/waterfall.pdf
 3. Plot.ly https://plot.ly/r/bar-charts/(滚动到底部)

更多示例:https://www.r-bloggers.com/waterfall-charts-in-style-of-the-economist-with-r/

library(latticeExtra)
library(waterfall)
data(rasiel) # Example data of the waterfall package
rasiel
#    label          value   subtotal
# 1  Net Sales       150    EBIT
# 2  Expenses       -170    EBIT 
# 3  Interest         18    Net Income
# 4  Gains            10    Net Income
# 5  Taxes            -2    Net Income

asTheEconomist(
               waterfallchart(value ~ label, data=rasiel,
                              groups=subtotal, main="P&L")
               )

enter image description here https://learnr.wordpress.com/2010/05/10/ggplot2-waterfall-charts/