dots_bars {dvmisc} | R Documentation |
Plot Points +/- Error Bars
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
dots_bars(y = NULL, bars = NULL, bars.lower = y - bars,
bars.upper = y + bars, truth = NULL, group.labels = NULL,
group.dividers = TRUE, subgroup.spacing = 1,
subgroup.labels = NULL, subgroup.pch = NULL, subgroup.col = NULL,
points.list = NULL, arrows.list = NULL, xaxis.list = NULL,
yaxis.list = xaxis.list, abline.dividers.list = NULL,
abline.truth.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 |
bars.lower |
Numeric vector or matrix (matching whichever type |
bars.upper |
Numeric vector or matrix (matching whichever type |
truth |
Numeric value specifying true value of parameter being estimated. If specified, a horizontal reference line is added to the plot. |
group.labels |
Character vector of labels for the groups. |
group.dividers |
Logical value for whether to add vertical lines distinguishing the groups. |
subgroup.spacing |
Numeric value controlling the amount of spacing between subgroups, with values > 1 corresponding to more spacing. |
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
|
arrows.list |
Optional list of inputs to pass to
|
xaxis.list |
Optional list of inputs to pass to
|
yaxis.list |
Optional list of inputs to pass to
|
abline.dividers.list |
Optional list of inputs to pass to
|
abline.truth.list |
Optional list of inputs to pass to
|
legend.list |
Optional list of inputs to pass to
|
... |
Additional arguments to pass to |
Value
Plot showing points +/- error bars across groups/subgroups.
Examples
# 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")