bpCI: Barplot confidence intervals

View source: R/plot_extra.R

bpCIR Documentation

Barplot confidence intervals

Description

Add confidence intervals (error bars) and group comparisons to barplots.

Usage

bpCI(
  x,
  horiz = FALSE,
  ci = TRUE,
  ci.u,
  ci.l,
  ci.width = 0.5,
  sig = FALSE,
  pvals,
  pch = "*",
  show.p = FALSE,
  ...
)

Arguments

x

the return value of barplot, i.e., a vector or matrix (when beside = TRUE) of all bar (or group) midpoints

horiz

logical; if TRUE, bpCI assumes horizontal bars

ci

logical; draw error bars (must give ci.u, ci.l)

ci.u, ci.l

a numeric vector or matrix having the same dimensions as x giving the upper and lower intervals, respectively

ci.width

width of the ends of the error bars, will depend on range(x)

sig

logical; if TRUE, draws group comparisons (must give pvals to plot sig stars)

pvals

p-values of group comparisons to be displayed as sig stars

pch

plotting character to be used for significance; default is * and uses same significance codes as printCoefmat

show.p

logical; if TRUE, p-values are shown and formatted with pvalr

...

additional graphical parameters passed to par

Examples

## generate data and p-values
hh <- t(VADeaths)[1:2, 5:1]
ci.l <- hh * 0.85
ci.u <- hh * 1.15
pvals <- pt(apply(hh, 2, diff), 1) / 5:1

bp <- barplot(hh, beside = TRUE, ylim = c(0, 100))
bpCI(bp, ci.u = ci.u, ci.l = ci.l, sig = TRUE, pvals = pvals)
bpCI(bp, ci.u = ci.u, ci.l = ci.l, sig = TRUE, pvals = pvals,
     show.p = TRUE, pch = FALSE)
mtext("Signif. codes:  0 '+++' 0.001 '++' 0.01 '+' 0.05 '.' 0.1 ' ' 1",
      side = 1, at = par('usr')[2], line = 2, adj = 1, cex = .8, font = 3)


bp <- barplot(hh <- cbind(x = c(465, 91) / 465 * 100,
                          y = c(200, 840) / 840 * 100,
                          z = c(37, 17) / 37 * 100),
              beside = TRUE, width = c(465, 840, 37),
              col = c(1, 2), ylim = c(0,130))

ci.l <- hh * 0.85
ci.u <- hh * 1.15
pv <- pt(-abs(apply(hh, 2, diff)), 1)

bpCI(bp, ci.u = ci.u, ci.l = ci.l, sig = TRUE, pvals = pv, ci.width = 100,
     col = 'red', lty = 'dashed', lwd = 2)
mtext("Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1",
      side = 1, at = par('usr')[2], line = 2, adj = 1, cex = .8, font = 3)


raredd/plotr documentation built on Nov. 19, 2023, 4:09 a.m.