Plot number of treated units over time or return a dataframe.

plot_treat_time(
  data,
  time_var,
  unit_treat,
  outlier_method = "iqr",
  show_legend = FALSE,
  theme_use = causalverse::ama_theme(),
  legend_title = "Point Type",
  legend_labels = c("Regular", "Outlier"),
  regular_size = 3,
  outlier_size = 5,
  regular_color = "black",
  outlier_color = "red",
  regular_shape = 16,
  outlier_shape = 17,
  title = "Random Time Assignment",
  xlab = "Time",
  ylab = "Number of Treated Units",
  output = "plot",
  ...
)

Arguments

data

Dataframe containing data.

time_var

Time variable for aggregating the number of treated units.

unit_treat

Variable indicating if the unit was treated in a specific time period.

outlier_method

Method for outlier detection ("iqr" or "z-score").

show_legend

Logical indicating whether to show legend.

theme_use

ggplot2 theme to use.

legend_title

Title for legend.

legend_labels

Labels for regular and outlier points.

regular_size

Size of regular points.

outlier_size

Size of outlier points.

regular_color

Color of regular points.

outlier_color

Color of outlier points.

regular_shape

Shape of regular points.

outlier_shape

Shape of outlier points.

title

Plot title.

xlab

X-axis label.

ylab

Y-axis label.

output

Type of output ("plot" or "dataframe").

...

Additional arguments to pass to ggplot2::labs.

Value

ggplot2 object or dataframe.

Examples

# Example usage:
if (FALSE) {
data <- data.frame(time = c(1,1,2,2,3,3), treat = c(0,1,1,1,0,0))
plot_treat_time(data, time_var = time, unit_treat = treat)
plot_treat_time(data, time_var = time, unit_treat = treat, output = "dataframe")
}