Of course! This is one of the most effective ways to visualize regression results. You want a coefficient plot (also called a dot-and-whisker plot) that uses color or another visual cue to highlight the significant coefficients.
Since your goal is the "easiest possible" method, I recommend using the modelsummary package. Its modelplot() function is fantastic, modern, and creates beautiful plots with minimal code.
We will follow these simple steps:
- Create a sample model (since I don't have yours).
- Use
modelplot() to create the base plot.
- Add one layer of
ggplot2 code to color the lines based on significance.
The Easiest & Most Flexible Method: modelsummary::modelplot()
This is my top recommendation. It's built on ggplot2, so it's easy to customize, and the initial plot is created with a single command.
Step 1: Load Libraries & Create Sample Model
First, let's set up a reproducible example that matches your description (a regression model with a logged outcome).
# Install packages if you haven't already
# install.packages("modelsummary")
# install.packages("ggplot2")
# install.packages("dplyr")
library(modelsummary)
library(ggplot2)
library(dplyr)
# --- Create a Sample Model for Demonstration ---
set.seed(42) # for reproducibility
dat <- data.frame(
# A logged outcome variable, as you described
log_outcome = rnorm(200, mean = 2, sd = 1),
var1_sig = runif(200, 0, 5), # This will be a significant predictor
var2_insig = rnorm(200), # This one will not be significant
var3_negative_sig = rnorm(200) # This will be significant and negative
)
# Create the relationship
dat$log_outcome <- dat$log_outcome + 0.2 * dat$var1_sig - 0.3 * dat$var3_negative_sig
# Fit the regression model (this is your `model_reg_ratio`)
model_reg_ratio <- lm(log_outcome ~ var1_sig + var2_insig + var3_negative_sig, data = dat)
Step 2: Create and Customize the Plot
Now for the magic. We'll create the plot and then add a color aesthetic based on whether the confidence interval crosses the null value of 1.
# Create the plot with exponentiated coefficients
p <- modelplot(model_reg_ratio,
exponentiate = TRUE, # This exponentiates the coefficients
conf_level = 0.95)
# --- This is the key part: Highlight significant results ---
# A coefficient is significant if its CI does not include 1
p <- p +
aes(color = (conf.low > 1 | conf.high < 1)) +
# Use clear colors: one for significant, one for not
scale_color_manual(values = c("TRUE" = "#D55E00", "FALSE" = "grey50")) +
# Add a vertical line at 1 (the "no effect" line)
geom_vline(xintercept = 1, linetype = "dashed") +
# Improve labels and theme
labs(
title = "Point Estimates of Regression Coefficients",
subtitle = "Significant coefficients are highlighted",
x = "Multiplicative Change in Outcome (Odds Ratio, etc.)",
y = "Predictor Variables",
color = "Significant (p < 0.05)" # Legend title
) +
theme_minimal()
# Display the final plot
print(p)
How This Code Works
modelplot(model_reg_ratio, exponentiate = TRUE): This is the core command. It automatically extracts the coefficients and confidence intervals from your model and exponentiates them.
p + aes(color = (conf.low > 1 | conf.high < 1)): This is the most important line. We add a ggplot2 aesthetic (aes) to the plot object p. We tell it to set the color based on a logical condition:
conf.low > 1: The lower bound of the confidence interval is greater than 1.
conf.high < 1: The upper bound of the confidence interval is less than 1.
- The
| means "OR". So, if either of these conditions is true, the coefficient is "significant," and the whole expression evaluates to TRUE.
scale_color_manual(...): This assigns specific colors to the TRUE (significant) and FALSE (not significant) values. I've chosen a distinct orange and a muted grey, which is great for presentations and publications.
geom_vline(xintercept = 1, ...): This adds a vertical dashed line at x=1. Since the coefficients are exponentiated, a value of 1 means "no effect." This line makes it instantly clear which CIs cross the null line.
Alternative Method: Using jtools (Your Original Package)
You can achieve the same result with jtools, building on your original code. The logic is identical: create the plot, access its data, add a significance column, and then map color to it.
library(jtools)
library(ggplot2)
library(dplyr)
# 1. Create the base plot from jtools
p_jtools <- jtools::plot_summs(model_reg_ratio, exp = TRUE)
# 2. Access the plot's data and add a 'significance' column
p_jtools$data <- p_jtools$data %>%
mutate(significance = case_when(
conf.low > 1 | conf.high < 1 ~ "Significant",
TRUE ~ "Not Significant"
))
# 3. Re-draw the plot using the new 'significance' column for color
final_plot_jtools <- p_jtools +
aes(color = significance) +
scale_color_manual(values = c("Significant" = "#D55E00", "Not Significant" = "grey50")) +
geom_vline(xintercept = 1, linetype = "dashed") +
labs(
title = "Point Estimates of Regression Coefficients",
x = "Multiplicative Change in Outcome",
color = "Status" # Legend title
) +
theme_bw() # jtools uses theme_bw() by default
print(final_plot_jtools)
Both methods produce a clear, publication-quality plot that effectively communicates your model's results. I personally prefer the modelsummary approach for its slightly more streamlined syntax, but both are excellent choices.