waterfall: Waterall plot

View source: R/plot.R

waterfallR Documentation

Waterall plot

Description

Draw two types of waterfall plots.

Usage

waterfall(
  x,
  type = 1L,
  col = c("red", "blue"),
  ...,
  arrows = type == 2L,
  rev = FALSE,
  plot = TRUE,
  panel.first = NULL,
  panel.last = NULL
)

Arguments

x

a numeric vector

type

type of waterfall plot; type = 1 draws sorted bars for values of x; type = 2 starts from 0 and draws bars according to the magnitude and direction of x

col

a vector of colors having 1) the same length as x; length 2 (for negative and positive values if type = 2) or otherwise to be used for color interpolation (colorRampPalette)

...

additional arguments passed to barplot, to/from other methods, or to par

arrows

logical; if TRUE, arrows are drawn in the direction of each bar

rev

logical; if TRUE, the order along the x-axis is reversed

plot

logical; if FALSE, nothing is plotted

panel.first

an expression to be evaluated after the plot axes are set up but before any plotting takes place; this can be useful for drawing background grids or scatterplot smooths; note that this works by lazy evaluation: passing this argument from other plot methods may well not work since it may be evaluated too early; see also plot.default

panel.last

an expression to be evaluated after plotting has taken place but before the axes, title, and box are added; see the comments about panel.first

Value

A matrix giving the coordinates of all the bar midpoints drawn (see barplot) and the order of x.

Examples

set.seed(1)
change <- runif(20, -1, 1) * 100
col <- c(PD = 'red', SD = 'blue', CR = 'chartreuse4')

## interpolation
waterfall(change, col = col)

## discrete breaks
waterfall(change, col = as.character(cut(change, c(-Inf, -50, 50, Inf), col)))
legend('top', names(col), fill = col, horiz = TRUE, bty = 'n', border = NA)
title(xlab = 'Patient', ylab = '% change', main = 'waterfall', line = 2)

## use return value to add an existing plot
wf <- waterfall(change, plot = FALSE)
text(wf[, 1L], 0, labels = sprintf('%0.1f', change[wf[, 2L]]),
     pos = ifelse(change[wf[, 2L]] > 0, 1, 3), cex = 0.5)


## type 2
waterfall(change, type = 2, col = col, panel.first = grid())
title(main = 'waterfall - type 2')
axis(2, las = 1)


raredd/rawr documentation built on March 4, 2024, 1:36 a.m.