dots_bars: Plot Points +/- Error Bars

Description Usage Arguments Value Examples

View source: R/dots_bars.R

Description

Creates plot showing user-specified points (e.g. means, medians, regression coefficients) along with user-specified error bars (e.g. standard deviations, min/max, 95% confidence intervals).

Usage

1
2
3
4
dots_bars(y = NULL, bars = NULL, bars.lower = y - bars, bars.upper = y +
  bars, group.labels = NULL, subgroup.labels = NULL, subgroup.pch = NULL,
  subgroup.col = NULL, points.list = NULL, arrows.list = NULL,
  axis.list = NULL, legend.list = NULL, ...)

Arguments

y

Numeric vector of y-values for different groups, or numeric matrix where each column contains y-values for clustered subgroups within a group.

bars

Numeric vector or matrix (matching whichever type y is) specifying the length of the error bar for each group/subgroup (i.e. distance from point to one end of error bar).

bars.lower

Numeric vector or matrix (matching whichever type y is) specifying the position of the lower end of the error bar for each group/subgroup.

bars.upper

Numeric vector or matrix (matching whichever type y is) specifying the position of the upper end of the error bar for each group/subgroup.

group.labels

Character vector giving labels for the groups.

subgroup.labels

Character vector giving labels for the subgroups.

subgroup.pch

Plotting symbol for different subgroups within each group.

subgroup.col

Plotting color for different subgroups within each group.

points.list

Optional list of inputs to pass to points function.

arrows.list

Optional list of inputs to pass to arrows function.

axis.list

Optional list of inputs to pass to axis function.

legend.list

Optional list of inputs to pass to legend function.

...

Additional arguments to pass to plot function.

Value

Plot showing points +/- error bars across groups/subgroups.

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
# Generate 100 values from normal distributions with different means, and 
# graph mean +/- standard deviation across groups 
dat <- cbind(rnorm(100, 2), rnorm(100, 2.5), rnorm(100, 1.75))
means <- apply(dat, 2, mean)
sds <- apply(dat, 2, sd)
fig1 <- dots_bars(y = means, bars = sds, main = "Mean +/- SD by Group",
                  ylab = "Mean +/- SD")
                  
# Simulate BMI values for males and females in 3 different age groups, and 
# graph mean +/- 95\% CI
sex <- as.factor(c(rep("Male", 300), rep("Female", 300)))
age <- as.factor(rep(c("Young", "Middle", "Old"), 2))
bmi <- c(rnorm(100, 25, 4), rnorm(100, 26, 4.25), rnorm(100, 27, 4.5),
         rnorm(100, 26.5, 4.5), rnorm(100, 27.25, 4.75), rnorm(100, 28, 5))
dat <- data.frame(sex = sex, age = age, bmi = bmi)
means <- tapply(dat$bmi, dat[, c("sex", "age")], mean)
ci.lower <- tapply(dat$bmi, dat[, c("sex", "age")],
                   function(x) t.test(x)$conf.int[1])
ci.upper <- tapply(dat$bmi, dat[, c("sex", "age")],
                   function(x) t.test(x)$conf.int[2])
fig2 <- dots_bars(y = means, bars.lower = ci.lower, bars.upper = ci.upper,
                  main = "BMI by Sex and Age",
                  ylab = "BMI (mean +/- CI)",
                  xlab = "Age group")

dvmisc documentation built on May 2, 2019, 5:51 p.m.

Related to dots_bars in dvmisc...