waterfall | R Documentation |
Draw two types of waterfall plots.
waterfall(
x,
type = 1L,
col = c("red", "blue"),
...,
arrows = type == 2L,
rev = FALSE,
plot = TRUE,
panel.first = NULL,
panel.last = NULL
)
x |
a numeric vector |
type |
type of waterfall plot; |
col |
a vector of colors having 1) the same length as |
... |
additional arguments passed to |
arrows |
logical; if |
rev |
logical; if |
plot |
logical; if |
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
|
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 |
A matrix giving the coordinates of all the bar midpoints drawn (see
barplot
) and the order
of x
.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.