View source: R/plot_parallel_trends.r
plot_parallel_trends | R Documentation |
The plot_parallel_trends()
function combines the various
trends data CSV files and plots parallel trends figures.
All treatment and all control groups can be combined so that there
is one control line and one treatment line by setting combine = TRUE
.
plot_parallel_trends(
dir_path,
covariates = FALSE,
save_csv = FALSE,
combine = FALSE,
pch = NA,
pch_control = NA,
pch_treated = NA,
control_colour = c("darkgrey", "lightgrey"),
control_color = NULL,
treatment_colour = c("darkred", "lightcoral"),
treatment_color = NULL,
lwd = 2,
xlab = NA,
ylab = NA,
title = NA,
xticks = 4,
date_format = "%Y-%m-%d",
xdates = NULL,
xaxlabsz = 0.8,
save_png = FALSE,
width = 800,
height = 600,
ylim = NULL,
yaxlabsz = 0.8,
ylabels = NULL,
yticks = 4,
ydecimal = 2,
legend_location = "topright",
simplify_legend = TRUE,
legend_cex = 0.7,
legend_on = TRUE,
treatment_indicator_col = "grey",
treatment_indicator_alpha = 0.5,
treatment_indicator_lwd = 2,
treatment_indicator_lty = 2,
interpolate = FALSE,
filepath = tempdir(),
filenamecsv = "combined_trends_data.csv",
filenamepng = "undid_plot.png"
)
dir_path |
A character filepath to the folder containing all of the trends data CSV files. |
covariates |
A logical value (defaults to |
save_csv |
A logical value (defaults to |
combine |
A logical value (defaults to |
pch |
An integer (0 to 25) or vector of integers (from 0 to 25)
which determine the style of points used on the plot. Setting to |
pch_control |
An integer (from 0 to 25) or vector of integers
(from 0 to 25) which determine the style of points used on the plot
for control silos. Takes value of pch if set to |
pch_treated |
An integer (from 0 to 25) or vector of integers
(from 0 to 25) which determine the style of points used on the plot
for treated silos. Takes value of pch if set to |
control_colour |
A character vector of colours
(defaults to |
control_color |
Overrides |
treatment_colour |
A character vector of colours
(defaults to |
treatment_color |
Overrides |
lwd |
An integer (defaults to |
xlab |
A character value for the x-axis label (defaults to |
ylab |
A character value for the y-axis label (defaults to |
title |
A character value for the title of the plot (defaults to |
xticks |
An integer value denoting how many ticks to display
on the x-axis (defaults to |
date_format |
A string value denoting the format with which to display
the dates along the x-axis (defaults to |
xdates |
Takes in a vector of date objects to be used as the dates shown
along the x-axis (defaults to |
xaxlabsz |
A double indicating the x-axis label sizes in comparison
to a standardized default size (defaults to |
save_png |
A logical value indicating whether or not to save the plot
as a PNG file (defaults to |
width |
An integer denoting the width of the saved PNG file. |
height |
An integer denoting the height of the saved PNG file. |
ylim |
A vector of two doubles defining the min and max range of the values on the y-axis. Defaults to the min and max values of the values to be plotted. |
yaxlabsz |
A double for specifying the y-axis label sizes
(defaults to |
ylabels |
A vector of values that you would like to appear
on the y-axis (defaults to |
yticks |
An integer denoting how many values to display
along the y-axis (defaults to |
ydecimal |
An integer value denoting to which decimal point the values along the y-axis are rounded to. |
legend_location |
A character value for determining the location
of the legend (defaults to |
simplify_legend |
A logical value which if set to |
legend_cex |
A double for adjusting the size of the text in the legend
compared to a standard default size. Defaults to |
legend_on |
A logical value for turning the legend on or off
(defaults to |
treatment_indicator_col |
A character value for determining the colour
of the dashed vertical lines showing when treatment times were
(defaults to |
treatment_indicator_alpha |
A double for for determining the
transparency level of the dashed vertical lines showing the treatment
times (defaults to |
treatment_indicator_lwd |
A double for selecting the line width
of the treatment indicator lines (defaults to |
treatment_indicator_lty |
An integer for the selecting the lty option,
i.e. the line style, for the treatment_indicator lines (defaults to |
interpolate |
A logical value (either |
filepath |
Filepath to save the CSV file. Defaults to |
filenamecsv |
A string filename for the combined trends data
Defaults to |
filenamepng |
A string filename for the PNG file output.
Defaults to |
A data frame built from the trends data from all CSV
files in the specified directory. If combine = FALSE
, the
data frame includes all silos joined by row. If combine = TRUE
,
the data frame merges treated silos into a single treatment group
and control silos into a single control group.
# Get path to example data included with package
dir_path <- system.file("extdata/staggered", package = "undidR")
# Basic usage with default parameters
plot_parallel_trends(dir_path)
# Custom plot with modified parameters
plot_parallel_trends(dir_path, combine = TRUE, lwd = 4,
xdates = as.Date(c("1989-01-01", "1991-01-01",
"1993-01-01", "1995-01-01",
"1997-01-01", "1999-01-01")))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.