g_waterfall: Horizontal waterfall plot

View source: R/g_waterfall.R

g_waterfallR Documentation

Horizontal waterfall plot

Description

[Stable]

This basic waterfall plot visualizes a quantity height ordered by value with some markup.

Usage

g_waterfall(
  height,
  id,
  col_var = NULL,
  col = getOption("ggplot2.discrete.colour"),
  xlab = NULL,
  ylab = NULL,
  col_legend_title = NULL,
  title = NULL
)

Arguments

height

(numeric)
vector containing values to be plotted as the waterfall bars.

id

(character)
vector containing identifiers to use as the x-axis label for the waterfall bars.

col_var

(factor, character, or NULL)
categorical variable for bar coloring. NULL by default.

col

(character)
color(s).

xlab

(string)
x label. Default is "ID".

ylab

(string)
y label. Default is "Value".

col_legend_title

(string)
text to be displayed as legend title.

title

(string)
text to be displayed as plot title.

Value

A ggplot waterfall plot.

Examples

library(dplyr)
library(nestcolor)

g_waterfall(height = c(3, 5, -1), id = letters[1:3])

g_waterfall(
  height = c(3, 5, -1),
  id = letters[1:3],
  col_var = letters[1:3]
)

adsl_f <- tern_ex_adsl %>%
  select(USUBJID, STUDYID, ARM, ARMCD, SEX)

adrs_f <- tern_ex_adrs %>%
  filter(PARAMCD == "OVRINV") %>%
  mutate(pchg = rnorm(n(), 10, 50))

adrs_f <- head(adrs_f, 30)
adrs_f <- adrs_f[!duplicated(adrs_f$USUBJID), ]
head(adrs_f)

g_waterfall(
  height = adrs_f$pchg,
  id = adrs_f$USUBJID,
  col_var = adrs_f$AVALC
)

g_waterfall(
  height = adrs_f$pchg,
  id = paste("asdfdsfdsfsd", adrs_f$USUBJID),
  col_var = adrs_f$SEX
)

g_waterfall(
  height = adrs_f$pchg,
  id = paste("asdfdsfdsfsd", adrs_f$USUBJID),
  xlab = "ID",
  ylab = "Percentage Change",
  title = "Waterfall plot"
)


tern documentation built on Sept. 24, 2024, 9:06 a.m.