bplot: Binomial confidence interval plot

View source: R/plot.R

bplotR Documentation

Binomial confidence interval plot

Description

Wrapper function to create table of binomial confidence intervals and draw as a forest plot.

Usage

bplot(
  data,
  varname,
  byvar,
  varname_label = names(varname),
  byvar_label = names(byvar),
  main = byvar_label,
  xlab = byvar_label,
  names = NULL,
  col = c("dodgerblue4", "dodgerblue2"),
  percent = FALSE,
  conf = 0.95,
  digits = ifelse(percent, 0L, 2L),
  show_overall = TRUE,
  show_missing = TRUE,
  alpha_missing = 1,
  widths = c(1, 2, 1),
  col.bar = c(grey(0.95), NA),
  group.bar = FALSE,
  ...
)

tabler_bincon(
  data,
  varname,
  byvar,
  varname_label = names(varname),
  byvar_label = names(byvar),
  main = byvar_label,
  xlab = byvar_label,
  names = NULL,
  col = c("dodgerblue4", "dodgerblue2"),
  percent = FALSE,
  conf = 0.95,
  digits = ifelse(percent, 0L, 2L),
  show_overall = TRUE,
  show_missing = TRUE,
  alpha_missing = 1,
  widths = c(1, 2, 1),
  col.bar = c(grey(0.95), NA),
  group.bar = FALSE,
  ...
)

Arguments

data

a matrix or data frame with variables varname and byvar

varname, byvar

one or more variables in data to calculate binomial confidence intervals by byvar; the rows variable(s) of the table;

note that varname variables should be factor-like, and byvar should be binary

varname_label, byvar_label

optional labels for each varname and byvar

main, xlab

the x-axis and title labels

names

optional vector of names for each panel to override defaults

col

a vector of colors for each varname; the first will be used for the overall (if show_overall = TRUE)

percent

logical; if TRUE, percentages will be shown instead of probabilities

conf

confidence level; passed to binconr

digits

the number of places past the decimal to keep

show_overall, show_missing

logical; if TRUE, rows with the overall and missing value confidence intervals are shown, respectively

alpha_missing

if show_missing = TRUE, the amount of alpha transparency added to missing value rows; passed to tcol

widths

a vector of widths for each panel, recycled as needed

col.bar

a vector of colors for background bars, recycled as needed

group.bar

logical; if TRUE, col.bar will be used once for each varname, recycled as needed

...

additional graphical parameters passed to par

Examples

set.seed(1)
dat <- mtcars[sample(nrow(mtcars), 100L, TRUE), ]
dat[1, 2] <- NA
vv  <- c('cyl', 'vs', 'gear', 'carb')
dat$gear <- factor(dat$gear, 3:6)

bplot(dat, vv, 'am')

bplot(
  dat, vv, 'am', percent = TRUE,
  col = c(0, seq_along(vv)) + 1L,
  main = 'Manual rate', xlab = 'Proportion of manual'
)

bplot(
  dat, setNames(vv, case(vv)), 'am',
  col = c('red', 'grey50', 'blue', 'grey50', 'blue'),
  conf = 0.9, alpha_missing = 0.4
)


raredd/rawr documentation built on May 9, 2024, 6:14 p.m.