Base plot() method for es_result objects returned by event_study()
(or the deprecated run_es()). Draws the event-study curve with pointwise
confidence bands as a static ggplot, or — with interactive = TRUE — an
interactive plotly chart with hover tooltips (requires the suggested
{plotly} package).
Arguments
- x
An
es_resultobject.- ci_level
Confidence level to display (default
0.95). Must be one of the levels the result was estimated at (conf_levelinevent_study()).- type
"errorbar"(default) or"ribbon". Static plots only.- time_axis
"relative"(default) for event time, or"calendar"for the original time values. See Details.- interactive
Logical; if
TRUE, return an interactive plotly chart instead of a ggplot. DefaultFALSE.- show_simultaneous
Logical; overlay the simultaneous bootstrap CI band (requires
bootstrap = TRUEin the originatingevent_study()call). DefaultFALSE.- ...
Further styling arguments: for static plots
vline_val,hline_val,vline_color,hline_color,linewidth,pointsize,alpha,barwidth,color,fill,errorbar_color,theme_style("bw","minimal", or"classic"); for interactive plotsmarkersize,show_ribbon,height,width, and the shared color arguments.vline_valdefaults to relative time -1, the last period before treatment, on whichever axis is in use.errorbar_colorcolours the bars alone and followscolorunless set.
Details
The default display is black error bars. type = "ribbon" switches to a
line with a shaded band and, unless color/fill say otherwise, to the
package's muted steel-blue palette. In either display color sets the
points (and the line), while errorbar_color can recolour the bars on
their own.
time_axis controls what the horizontal axis shows. The default
"relative" plots event time (periods since treatment) and labels the axis
"Relative Time to Treatment". "calendar" instead plots the original time
values (e.g. 2010, or a Date), labels the axis with the time column's
name, and moves the dashed vertical reference line to the treatment period.
It is available whenever every treated unit adopts in the same period —
universal timing, or a staggered design that happens to have a single
cohort — and errors otherwise, because with several cohorts one relative
period corresponds to several calendar periods.
Examples
if (FALSE) { # \dontrun{
res <- event_study(y ~ 1 | id + year, data = df, time = year, timing = g,
estimator = "cs")
plot(res)
plot(res, type = "ribbon", ci_level = 0.9)
plot(res, color = "#1B4965", errorbar_color = "grey50")
plot(res, interactive = TRUE)
# Universal timing: label the axis with calendar years instead
uni <- event_study(y ~ d | id + year, data = df, time = year,
timing = 2010)
plot(uni, time_axis = "calendar")
} # }