-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
157 lines (112 loc) · 2.18 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "70%"
)
```
# ggwaterfall
<!-- badges: start -->
<!-- badges: end -->
ggwaterfall provides tools to make waterfall charts based on ggplot2
## Example
Generate some random data.
```{r example - simulate data}
library(ggwaterfall)
library(data.table)
library(magrittr)
library(ggplot2)
# simulate data
set.seed(1L)
nitems <- 5
ntime <- 2
DT <-
data.table(
group = rep(c("Group 1", "Group 2"), each = nitems),
item = paste0("item ", rep(letters[1:nitems], each = ntime)),
time = rep(1:ntime, times = nitems),
value = 6 + rnorm(nitems * ntime)
)
DT
```
```{r}
waterfall(
data = DT,
detail_var = "item",
base_var = "time",
value_var = "value"
) %>%
plot()
```
Plot a more advanced waterfall charts with multiple periods.
```{r}
# simulate new data
set.seed(1L)
nitems <- 4
ntime <- 3
DT <-
data.table(
group = rep(c("Group 1", "Group 2"), each = nitems),
item = paste0("item ", rep(letters[1:nitems], each = ntime)),
time = rep(1:ntime, times = nitems),
value = 6 + rnorm(nitems * ntime)
)
DT
```
Plot a simple waterfall chart.
```{r}
waterfall(
data = DT,
detail_var = "item",
base_var = "time",
value_var = "value"
) %>%
plot()
```
You can make use of facetting with `by_var` arguments:
```{r}
waterfall(
data = DT,
detail_var = "item",
base_var = "time",
by_var = "group",
value_var = "value"
) %>%
plot()
```
Or flip the chart with flip = TRUE:
```{r}
waterfall(
data = DT,
detail_var = "item",
base_var = "time",
by_var = "group",
value_var = "value"
) %>%
plot(
select = (time > 1 | is_aggr),
flip = TRUE,
)
```
Use can still adapt the chart with comomn ggplot2 API:
```{r}
DTwf <-
waterfall(
data = DT,
detail_var = "item",
base_var = "time",
by_var = "group",
value_var = "value"
)
DTwf %>%
plot(
flip = TRUE,
) +
ggtitle("Add this title here")
```
```