to_waterfall: Make waterfall data tibble from a tibble of cash flows

Description Usage Arguments Value Examples

View source: R/waterfall.R

Description

The only requirement for this function to work is that the first row and last row of the tibble represent the cash in and cash out. In other words the Base and the Total when talking about sales modeling.

Usage

1

Arguments

data

the data tibble to operate on

Value

a new data tibble with columns necessary to create a waterfall visualization

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
datadf <-
  tibble::tibble(
    desc = c(
      "starting_net_income",
      "write_offs",
      "sales",
      "COGS",
      "overhead",
      "taxes",
      "bonuses",
      "other_income",
      "ending_net_income"
    ),
    amount = c(1200, -2300, 11000, -9000, -1900, -1200, -3000, 7000, 1800)
  )
to_waterfall(datadf)
# Change order
datadf2 <- to_waterfall(datadf)
firstindex <- which(datadf$desc == "sales")
datadf2[c(firstindex, setdiff(seq_along(datadf$amount), firstindex)), ]

DoktorMike/datools documentation built on Feb. 28, 2021, 8:39 a.m.