strip_error: Strip plots with error bars.

View source: R/plot_functions.R

strip_errorR Documentation

Strip plots with error bars.

Description

strip_error constructs strip plots with error bars showing 95 confidence intervals around mean values.

Usage

strip_error(
  object = NULL,
  formula = NULL,
  data = NULL,
  pch = 20,
  size = 1,
  alpha = 0.7,
  col = "indianred3",
  ...
)

Arguments

object

When chaining, this holds an object produced in the earlier portions of the chain. Most users can safely ignore this argument. See details and examples.

formula

A formula with shape: y ~ x or y ~ x|z where y is a numerical variable and both x and z are factors.

data

A data frame where the variables in the formula can be found.

pch

Point character passed to gf_point or gf_jitter.

size

Size of the symbol (pch) for representing data values.

alpha

Opacity of the symbol (0 = invisible, 1 = opaque).

col

A colour or formula used for mapping colour.

...

Additional information passed to gf_jitter or gf_point.

Examples

data(energy, package = "ISwR")
require(sjlabelled, quietly = TRUE)
energy <- energy |>
  var_labels(
    expend = "Energy expenditure (MJ/day)",
    stature = "Stature"
  )

energy |>
  strip_error(expend ~ stature, col = "red")

t.test(expend ~ stature, data = energy)

## Adding an horizontal line to show significant difference:
energy |>
  strip_error(expend ~ stature, col = "red") |>
  gf_star(1, 13, 2, 13.2, 13.4, "**")

data(birthwt, package = "MASS")
require(dplyr, quietly = TRUE)
birthwt <- birthwt |>
  mutate(
    smoke = factor(smoke, labels = c("Non-smoker", "Smoker")),
    Race = factor(race > 1, labels = c("White", "Non-white"))
  ) |>
  var_labels(
    bwt = "Birth weight (g)",
    smoke = "Smoking status"
  )

birthwt |>
  strip_error(bwt ~ smoke | Race, col = "darksalmon")

birthwt |>
  strip_error(bwt ~ smoke, col = ~Race)

birthwt |>
  strip_error(bwt ~ smoke, pch = ~Race, col = ~Race)

birthwt |>
  strip_error(bwt ~ smoke | Race)

pubh documentation built on Oct. 8, 2024, 9:08 a.m.