
Publication-Ready Regression Discontinuity Plot
rd_plot.RdCreates a publication-ready RD plot with optimal binning, local polynomial
fit, confidence bands, and a cutoff line. Wraps rdrobust::rdplot
from the rdrobust package with enhanced ggplot2 aesthetics. When
rdrobust is not installed a simple local polynomial via lm is
used instead.
Usage
rd_plot(
y,
x,
cutoff = 0,
nbins = NULL,
poly_order = 4L,
ci_shade = TRUE,
title = NULL,
xlab = "Running Variable",
ylab = "Outcome",
cutoff_color = "red",
color_sides = TRUE,
rdplot_args = list()
)Arguments
- y
Numeric vector. Outcome variable.
- x
Numeric vector. Running variable. Values are shifted internally so the cutoff is at zero.
- cutoff
Numeric. RD cutoff value on the original scale. Default
0.- nbins
Integer or
NULL. Number of bins per side. IfNULL(default), MSE-optimal binning fromrdrobust::rdplotis used.- poly_order
Integer. Polynomial order for the smooth fit lines. Default
4.- ci_shade
Logical. Add confidence band shading around the polynomial fit. Default
TRUE.- title
Character or
NULL. Plot title.- xlab
Character. X-axis label. Default
"Running Variable".- ylab
Character. Y-axis label. Default
"Outcome".- cutoff_color
Character. Color of the vertical cutoff line. Default
"red".- color_sides
Logical. Use different colors for the control (left) and treated (right) sides. Default
TRUE.- rdplot_args
List. Additional named arguments forwarded to
rdrobust::rdplot(ignored when rdrobust is not available).