| plot.coresynth | R Documentation |
Plot a coresynth model
## S3 method for class 'coresynth'
plot(
x,
type = c("trend", "gap", "weights", "pred_weights"),
colors = NULL,
labels = NULL,
linetypes = NULL,
vline = list(),
vline_offset = 0,
hline = list(),
fill = NULL,
top_n = Inf,
align = FALSE,
show_donors = 0,
...
)
x |
A |
type |
One of |
colors |
For |
labels |
For |
linetypes |
For |
vline |
Aesthetic overrides for the vertical treatment-time line, as a
list passed to |
vline_offset |
For |
hline |
Aesthetic overrides for the horizontal zero line in |
fill |
For |
top_n |
For |
align |
For |
show_donors |
For |
... |
Ignored. |
A ggplot2 plot object.
set.seed(1)
panel <- expand.grid(unit = 1:10, year = 1:20)
panel$treated <- as.integer(panel$unit == 5 & panel$year > 15)
panel$gdp <- panel$unit + 0.5 * panel$year +
rnorm(nrow(panel)) + 3 * panel$treated
fit <- scm_fit(gdp ~ treated | unit + year, data = panel, method = "scm")
plot(fit, type = "trend")
plot(fit, type = "gap")
plot(fit, type = "weights")
plot(fit, type = "weights", top_n = 5)
# Predictor (V) weights: which predictors the fit leans on
plot(fit, type = "pred_weights")
# Overlay the five largest donors behind the treated/synthetic series
plot(fit, type = "trend", show_donors = 5)
# SDID: align the synthetic series on the lambda-weighted pre-period level
fit_sdid <- scm_fit(gdp ~ treated | unit + year, data = panel, method = "sdid")
plot(fit_sdid, type = "trend", align = TRUE)
plot(fit_sdid, type = "gap", align = TRUE)
# Customize series colors, legend text, line types, and reference lines
plot(fit, type = "trend",
colors = c(treated = "black"),
labels = c(treated = "Unit 5"),
vline = list(color = "red", linetype = "dashed"))
# Draw both series solid, or restyle the gap line
plot(fit, type = "trend", linetypes = c(synthetic = "solid"))
plot(fit, type = "gap", linetypes = "dashed")
# Move the treatment line one period earlier (last pre-treatment period),
# pin it to an absolute time, or drop it entirely
plot(fit, type = "trend", vline_offset = -1)
plot(fit, type = "trend", vline = list(xintercept = 15.5))
plot(fit, type = "trend", vline = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.