I'll help you create a coefficient plot that shows all your coefficients with their significance status. Since you want the easiest approach, I'll use jtools::plot_summs() which handles the exponentiation automatically and makes significance highlighting straightforward.
Easiest Approach: Using jtools::plot_summs()
library(jtools)
library(ggplot2)
library(dplyr)
# Create the base plot with exponentiated coefficients
p <- jtools::plot_summs(
model_reg_ratio,
exp = TRUE, # Exponentiates logged coefficients
scale = TRUE, # Standardizes if you want
show.values = TRUE, # Shows coefficient values
digits = 2 # Number of decimal places
)
# Add significance highlighting
# Since exp = TRUE, significance means CI doesn't cross 1
p$data <- p$data %>%
mutate(significance = case_when(
conf.low > 1 | conf.high < 1 ~ "Significant",
TRUE ~ "Not Significant"
))
# Create the final plot with significance colors
final_plot <- p +
aes(color = significance) +
scale_color_manual(
values = c("Significant" = "#D55E00", "Not Significant" = "grey60"),
name = "Significance"
) +
labs(
title = "Regression Coefficients (Exponentiated)",
x = "Multiplicative Effect (Odds Ratio)",
y = "Variables"
) +
theme_minimal() +
# Add a vertical line at 1 (no effect)
geom_vline(xintercept = 1, linetype = "dashed", alpha = 0.7)
print(final_plot)
Alternative: Manual Approach with broom + ggplot2
If you want more control or your model isn't supported by jtools, here's a manual approach:
library(broom)
library(ggplot2)
library(dplyr)
# Extract coefficients and confidence intervals
coef_data <- tidy(model_reg_ratio, conf.int = TRUE) %>%
filter(term != "(Intercept)") %>% # Remove intercept if desired
mutate(
# Exponentiate estimates and confidence intervals
estimate_exp = exp(estimate),
conf.low_exp = exp(conf.low),
conf.high_exp = exp(conf.high),
# Determine significance (CI doesn't cross 1 after exponentiation)
significant = (conf.low_exp > 1 | conf.high_exp < 1),
significance = ifelse(significant, "Significant", "Not Significant")
)
# Create the plot
ggplot(coef_data, aes(x = estimate_exp, y = reorder(term, estimate_exp))) +
geom_point(aes(color = significance), size = 3) +
geom_errorbarh(
aes(xmin = conf.low_exp, xmax = conf.high_exp, color = significance),
height = 0.2
) +
geom_vline(xintercept = 1, linetype = "dashed", alpha = 0.7) +
scale_color_manual(
values = c("Significant" = "#D55E00", "Not Significant" = "grey60"),
name = "Significance"
) +
labs(
title = "Regression Coefficients (Exponentiated)",
x = "Multiplicative Effect (Odds Ratio)",
y = "Variables"
) +
theme_minimal() +
# Add coefficient values as text
geom_text(
aes(label = round(estimate_exp, 2), color = significance),
hjust = -0.2, size = 3
)
Even Simpler: Using coefplot Package
The coefplot package is specifically designed for this:
library(coefplot)
# Simple coefficient plot
coefplot(model_reg_ratio,
intercept = FALSE, # Don't show intercept
exp = TRUE) + # Exponentiate coefficients
labs(
title = "Regression Coefficients (Exponentiated)",
x = "Multiplicative Effect (Odds Ratio)"
) +
geom_vline(xintercept = 1, linetype = "dashed", alpha = 0.7)
Customizing Further
If you want to add more customization to the jtools approach:
# Enhanced version with more customization
p <- jtools::plot_summs(
model_reg_ratio,
exp = TRUE,
show.values = TRUE,
digits = 3,
robust = TRUE # Use robust standard errors if needed
)
# Add significance and customize
p$data <- p$data %>%
mutate(
significance = case_when(
conf.low > 1 | conf.high < 1 ~ "Significant",
TRUE ~ "Not Significant"
),
# Create more detailed labels
effect_size = case_when(
abs(log(est)) > log(1.5) & significance == "Significant" ~ "Large Effect",
abs(log(est)) > log(1.2) & significance == "Significant" ~ "Medium Effect",
significance == "Significant" ~ "Small Effect",
TRUE ~ "Not Significant"
)
)
final_plot <- p +
aes(color = effect_size, alpha = significance) +
scale_color_manual(
values = c(
"Large Effect" = "#D55E00",
"Medium Effect" = "#E69F00",
"Small Effect" = "#56B4E9",
"Not Significant" = "grey60"
),
name = "Effect Size"
) +
scale_alpha_manual(
values = c("Significant" = 1.0, "Not Significant" = 0.5),
guide = "none" # Hide alpha legend
) +
labs(
title = "Regression Coefficients with Effect Sizes",
subtitle = "Coefficients are exponentiated (multiplicative effects)",
x = "Multiplicative Effect (Odds Ratio)",
y = "Variables"
) +
theme_minimal() +
geom_vline(xintercept = 1, linetype = "dashed", alpha = 0.7, color = "red") +
theme(
plot.title = element_text(size = 14, face = "bold"),
axis.text = element_text(size = 11)
)
print(final_plot)
Key Points
- Exponentiation: Using
exp = TRUE in jtools::plot_summs() automatically exponentiates your logged coefficients
- Significance: Since coefficients are exponentiated, significance means the confidence interval doesn't cross 1 (not 0)
- Visual clarity: The dashed vertical line at 1 shows the "no effect" threshold
- Color coding: Significant coefficients are highlighted in color, non-significant in grey
The first approach with jtools::plot_summs() is definitely the easiest and handles most of the work automatically. Just run that code with your model_reg_ratio and you'll get a clean, publication-ready coefficient plot!