Skip to contents

Create a Waterfall Chart

Usage

v_waterfall(
  vc,
  mapping = NULL,
  data = NULL,
  name = NULL,
  ...,
  serie_id = NULL,
  data_id = NULL
)

Arguments

vc

A chart initialized with vchart().

mapping

Default list of aesthetic mappings to use for chart.

data

Default dataset to use for chart. If not already a data.frame, it will be coerced to with as.data.frame.

name

Name for the serie, only used for single serie (no color/fill aesthetic supplied).

...

Additional parameters for the serie.

data_id, serie_id

ID for the data/serie, can be used to further customize the chart with v_specs().

Value

A vchart() htmlwidget object.

Examples


library(vchartr)

balance <- data.frame(
  desc = c("Starting Cash",
           "Sales", "Refunds", "Payouts", "Court Losses",
           "Court Wins", "Contracts", "End Cash"),
  amount = c(2000, 3400, -1100, -100, -6600, 3800, 1400, 2800)
)

vchart(balance) %>% 
  v_waterfall(aes(x = desc, y = amount))
# With total values and formatting data.frame( x = c("Feb.4", "Feb.11", "Feb.20", "Feb.25", "Mar.4", "Mar.11", "Mar.19", "Mar.26", "Apr.1", "Apr.8", "Apr.15", "Apr.22", "Apr.29", "May.6", "total"), total = c(TRUE, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, TRUE), y = c(45L, -5L, 2L, -2L, 2L, 2L, -2L, 1L, 1L, 1L, 2L, 1L, -2L, -1L, NA) ) %>% vchart() %>% v_waterfall( aes(x = x, y = y, total = total), stackLabel = list( valueType = "absolute", formatMethod = JS("text => text + '%'") ) ) %>% v_specs_legend(visible = TRUE)