This function generates a faceted line plot for a given dataset, allowing the user to specify the x-axis, y-axis, grouping variable, and facet variable. Additionally, users can include standard errors and customize labels.

plot_trends_across_group(
  data,
  x_var,
  y_var,
  grouping_var,
  facet_var,
  se = NULL,
  include_legend = TRUE,
  title = "Dependent Variable across Years by Group and Industry",
  x_label = "Year",
  y_label = "Dependent Variable",
  theme = causalverse::ama_theme(),
  ...
)

Arguments

data

A data frame containing the data to be plotted.

x_var

A character string specifying the x-axis variable.

y_var

A character string specifying the y-axis variable.

grouping_var

A character string specifying the grouping variable.

facet_var

A character string specifying the facet variable.

se

A character string specifying the standard error variable, or NULL (default) if not provided.

include_legend

Logical. If TRUE, includes the legend, otherwise it does not.

title

Character string specifying the main plot title.

x_label

Character string specifying the x-axis label.

y_label

Character string specifying the y-axis label.

theme

A ggplot2 theme. Defaults to ama_theme.

...

Additional arguments passed to labs.

Value

A ggplot object.

Examples

if (FALSE) {
# Create a small sample dataset
sample_data <- data.frame(
  year = rep(2001:2005, each = 2),
  dependent_variable = rnorm(10, mean = 50, sd = 10),
  group = rep(c("treated", "control"), times = 5),
  industry = rep(c("Tech", "Healthcare"), each = 5)
)

# Use the function
plot_trends_across_group(data = sample_data,
                        x_var = "year",
                        y_var = "dependent_variable",
                        grouping_var = "group",
                        facet_var = "industry",
                        title = "Sample Title")
}