panelview | R Documentation |
Visualizes missing values, treatment and outcome variables, and their relationships in panel data
panelview(data, formula = NULL, Y = NULL, D = NULL,
X = NULL, index,
ignore.treat = FALSE, type = "treat",
outcome.type = "continuous",
treat.type = NULL, by.group = FALSE, by.group.side = FALSE,
by.timing = FALSE, theme.bw = TRUE,
xlim = NULL, ylim = NULL,
xlab = NULL, ylab = NULL,
gridOff = FALSE, legendOff = FALSE,
legend.labs = NULL, main = NULL,
pre.post = NULL, id = NULL, show.id = NULL,
color = NULL, axis.adjust = FALSE, axis.lab = "both",
axis.lab.gap = c(0, 0), axis.lab.angle = NULL, shade.post = FALSE,
cex.main = 15, cex.main.sub = 12, cex.axis = 8,
cex.axis.x = NULL, cex.axis.y = NULL,
cex.lab = 12, cex.legend = 12, background = NULL,
style = NULL, by.unit = FALSE, lwd = 0.2, leave.gap = FALSE,
display.all = NULL, by.cohort = FALSE,
collapse.history = NULL, report.missing = FALSE)
data |
a data frame. The panel does not have to be balanced. |
formula |
an object of class "formula": a symbolic description of the model to be fitted. The first variable on the right-hand-side is designated as the treatment indicator if |
Y |
variable name of the outcome. Ignored if |
D |
variable name of the treatment. Ignored if |
X |
variable name of the time-varying covariates. Ignored if |
index |
a two-element string vector specifying the unit (group) and time indicators. Must be of length 2. |
ignore.treat |
a logical flag indicating whether there is a treatment variable. Default value is |
type |
a string that specifies the type of the plot. Must be either |
outcome.type |
a string that specifies the type of outcome variable. Must be either |
treat.type |
a string that specifies the type of treatment variable. Must be either |
by.group |
a logic flag indicating whether the data should be plotted in a column in separate groups based on treatment status changes for the outcome plot. |
by.group.side |
a logical flag indicating whether to arrange subfigures of |
by.timing |
a logic flag indicating whether the units should be sorted based on the timing of receiving the treatment for the treat plot. |
theme.bw |
a logical flag specifying whether to use a black-and-white theme. |
xlim |
a two-element numeric vector specifying the range of x-axis. When the class of time variable is string, must specify the range of strings to be shown, e.g. |
ylim |
a two-element numeric vector specifying the range of y-axis. |
xlab |
a string indicating the label of the x-axis. |
ylab |
a string indicating the label of the y-axis. |
gridOff |
a logical flag controlling whether to show the grid lines on the treat plot.. |
legendOff |
a logical flag controlling whether to show the legend. |
legend.labs |
a vector specifying the legend labels. Ignored when |
main |
a string that controls the title of the plot. |
pre.post |
a logical flag indicating whether to distinguish control status of treated units from that of control units. Only used for staggered data in the treat and outcome plots. |
id |
a vector specifying units to be shown in the plot. Useful when the number of units is very large. |
show.id |
a numeric vector or sequence specifying the sorted order of units to be shown in the |
color |
a string vector specifying color setting for the plot. |
axis.adjust |
a logic flag indicating whether to adjust labels on the x-axis. Useful when the class of time variable is string and there are many time periods. |
axis.lab |
a string indicating whether labels on the x- and y-axis will be shown. There are four options: |
axis.lab.gap |
a numeric vector setting the gaps between labels on the x- or y-axis for the plot. Default is |
axis.lab.angle |
a numeric value setting the angle (degrees) of the labels shown on the x-axis. Must be between 0 and 90. |
shade.post |
a logical flag controlling whether to shade the post-treatment periods. Ignored if |
cex.main |
a numeric value (pt) specifying the fontsize of the main title. |
cex.main.sub |
a numeric value (pt) specifying the fontsize of the subtitles. Ignored if |
cex.axis |
a numeric value (pt) specifying the fontsize of the texts on the axes; overwritten by |
cex.axis.x |
a numeric value (pt) specifying the fontsize of the texts on the x-axis. |
cex.axis.y |
a numeric value (pt) specifying the fontsize of the texts on the y-axis. |
cex.lab |
a numeric value (pt) specifying the fontsize of the axis titles. |
cex.legend |
a numeric value (pt) specifying the fontsize of the legend. |
background |
a character specifying the background color. |
by.unit |
a logic flag indicating whether to plot by each specified units or to plot mean D and Y against time in the same graph. |
style |
a string vector to set line/connected line/bar styles for the outcome and treatment variables. |
lwd |
a numeric value (pt) specifying the line width when plotting time series of treatment and outcome variables. |
leave.gap |
a logical flag indicating whether to keep time gaps as white bars if time is not evenly distributed (possibly due to missing data). Default value is |
display.all |
a logical flag indicating whether to show all units if the number of units is more than 500, otherwise we randomly select 500 units to present. |
by.cohort |
a logical flag indicating whether to plot the average outcome lines based on unique treatment histories in an "outcome" plot. |
collapse.history |
a logical flag indicating whether to collapse units by treat history in a "treat"" plot. |
report.missing |
a logical flag indicating whether to report missingness in the included variables. |
panelview visualizes the treatment status, missing values, and raw outcome data of a time-series cross-sectional dataset.
Hongyu Mou <hongyumou@g.ucla.edu>
Licheng Liu <liulch@mit.edu>
Yiqing Xu <yiqingxu@stanford.edu>
Hongyu Mou, Licheng Liu and Yiqing Xu (2023). "Panel Data Visualization in R (panelView) and Stata (panelview)." Journal of Statistical Software, 107(7), pp. 1–20. <doi:10.18637/jss.v107.i07>
library(panelView)
data(panelView)
panelview(turnout ~ policy_edr + policy_mail_in + policy_motor,
data = turnout, index = c("abb","year"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.