| lpr_stack | R Documentation |
This function creates dataframes which can then be input in lapop_stack() for plotting variables categories with a stacked bar graph using LAPOP formatting.
lpr_stack(
data,
outcome,
xvar = NULL,
sort = "y",
order = "hi-lo",
filesave = "",
keep_nr = FALSE
)
data |
The data that should be analyzed. It requires a survey object from lpr_data() function. |
outcome |
Vector of variables be plotted. |
xvar |
Character. Outcome variable will be broken down by this variable. Default is NULL |
sort |
Character. On what value the bars are sorted: the x or the y. Options are "y" (default; for the value of the outcome variable), "xv" (for the underlying values of the x variable), "xl" (for the labels of the x variable, i.e., alphabetical). |
order |
Character. How the bars should be sorted. Options are "hi-lo" (default) or "lo-hi". |
filesave |
Character. Path and file name to save the dataframe as csv. |
keep_nr |
Logical. If TRUE, will convert "don't know" (missing code .a) and "no response" (missing code .b) into valid data (value = 99) and use them in the denominator when calculating percentages. The default is to examine valid responses only. Default: FALSE. |
Returns a data frame, with data formatted for visualization by lapop_stack
Robert Vidigal, robert.vidigal@vanderbilt.edu
require(lapop); data(ym23)
# Set Survey Context
ym23lpr<-lpr_data(ym23)
# Multiple outcomes stacked
lpr_stack(data = ym23lpr,
outcome = c("b12", "b18"))
# Single outcome over years
lpr_stack(data = ym23lpr,
outcome = "q14f",
xvar="year")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.