How to draw a waterfall with R language & EXCEL
In this issue, the editor will bring you about how to draw waterfalls in R language & EXCEL. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Waterfall diagram is a process chart that makes one state evolve into another state under many reasons and factors. In this process, we can understand what are the main factors that lead to the change and the strength of the influence. There are three packages that can be done in R language, which are waterfall,waterfalls-based ggplot2 drawing system and rAmCharts (drawing dynamic interactive waterfall diagram). Finally, it introduces how to draw waterfall diagram with EXCEL.
1. Waterfall package drawing
This package draws the simplest waterfall diagram. It is not flexible enough to modify the properties of the picture. It is not recommended to use it only to understand it.
Library (waterfall)
Mydata=data.frame (Item=as.factor (c ('Before','Factor axiomagy) Factor Bobby, Factor Cohen, Factor D')
'Factor Eleven, Fine, and G')
Data=c (325,32mics, 105pr. 38pr. 86pr. 97232389).
Waterfallchart (Item~data,data=mydata)
2. Waterfalls package
This package is based on ggplot2, so all the functions of ggplot2 and the functions in its extension package can be used to modify the waterfall diagram. Another reason is that there is only one function in this package, waterfallchart, which contains more than 20 parameters that basically meet the requirements of drawing a waterfall diagram. If you want to further beautify the picture, you can refer to other functions in the ggplot2 family.
Library (waterfalls)
Library (ggplot2)
Library (ggthemes)
Waterfall (.data = mydata
Rect_text_labels = paste (levels (mydata$Item),'\ nMy data)
Fill_colours = c ('darkslateblue','chocolate','chocolate','chartreuse'
'chartreuse','chartreuse','chartreuse','chartreuse')
Calc_total = TRUE, total_rect_color = "darkslateblue"
Total_rect_text = paste ('After','\ nsum (mydata$data))
Total_rect_text_color = "black"
Total_axis_text = "After"
Rect_width = 0.9
Draw_axis.x = "behind"
Rect_border = "white"
Fill_by_sign = FALSE) +
Theme_map () +
Geom_hline (yintercept = 0, colour = 'skyblue')
III. RAmCharts
This package can make a dynamic waterfall diagram, but the difficulty lies in the construction of the data form, with an extra column of symbols.
Mydata=data.frame ("label=c") ('Before','Factor Aids,' factors', factors, D'.
'Factor EffectiveFormula Fengfei Fengfei Factor Gongji after')
Value=c (325, 32, 105, 38, 86, 97, 232, 389, 1030)
Operation=c ('total','minus','minus','plus','plus','plus','plus','plus','total'))
AmWaterfall (data = mydata, show_values = TRUE
4. Use EXCEL to make
Select all the columns except the shaded section and click to insert the stacked bar chart, where the data formula for the Dummy column
= IF (B3