bpCI: Barplot confidence intervals

Description Usage Arguments Examples

View source: R/plot_extra.R

Description

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

Usage

1
2
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
## 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, 2018, 11:02 a.m.