Learn R Programming

pubrplot (version 0.0.1)

plot_or: Plot Odds Ratios from Logistic Regression

Description

This function fits univariate and multivariate logistic regression models and plots odds ratios with 95% confidence intervals. Reference levels can optionally be displayed.

Usage

plot_or(
  data,
  outcome,
  predictors,
  label_vjust = -0.8,
  label_hjust = 0.5,
  label_size = 3.5,
  label_color = "black",
  point_color = c("steelblue", "firebrick"),
  ref = TRUE
)

Value

A ggplot object showing odds ratios with confidence intervals.

Arguments

data

A data frame containing the outcome and predictors.

outcome

Name of the binary outcome variable (as string).

predictors

Vector of predictor variable names (as strings).

label_vjust

Vertical adjustment for labels (default -0.8).

label_hjust

Horizontal adjustment for labels (default 0.5).

label_size

Size of the text labels (default 3.5).

label_color

Color of the text labels (default "black").

point_color

Colors for points corresponding to univariate and multivariate models (default c("steelblue", "firebrick")).

ref

Logical, whether to show reference levels (default TRUE).

Examples

Run this code
# Load built-in infertility dataset
infert1 <- datasets::infert
infert$case <- factor(infert$case, levels = c(0,1), labels = c("Control","Infertile"))
infert$induced <- factor(infert$induced, levels = c(0,1), labels = c("No","Yes"))
infert$spontaneous <- factor(infert$spontaneous, levels = c(0,1), labels = c("No","Yes"))

# Plot with reference levels
plot_or(
  data = infert1,
  outcome = "case",
  predictors = c("parity","induced","spontaneous","age"),
  ref = TRUE
)

# Plot without reference levels
plot_or(
  data = infert1,
  outcome = "case",
  predictors = c("parity","induced","spontaneous","age"),
  ref = FALSE
)

Run the code above in your browser using DataLab