These are helper functions to wrangle labels and produce visualizations of AmericasBarometer data following LAPOP Labβs editorial guidelines.
π Package website: https://lapop-central.github.io/lapop/
π οΈ Installation
To install the package in your R console, run:
devtools::install_github("lapop-central/lapop",
force = TRUE,
build_vignettes = TRUE)
βοΈ Workflow: AmericasBarometer Variable & Value Labels
For the full online guide, see:
π LAPOP Data Guide for R Users (pkgdown article)
1. Data Structure
AmericasBarometer datasets are distributed in Stata .dta
format with multilingual metadata (question wording and response options) embedded as attributes. These support cross-national and longitudinal comparability.
2. Preferred Loading Method
Use:
readstata13::read.dta13()
to preserve the full metadata structure.
Other methods such as haven::read_dta()
or rio::import()
may fail to import the STATA attributes.
3. Variable Labels (Question Wording)
- Stored in the
expansion.fields
attribute. - Use
lpr_extract_notes()
to convert into a tidy data frame. - Assign preferred language labels with
lpr_set_attr()
using the appropriatenoteid
.
4. Value Labels (Response Options)
- Stored in the
label.table
attribute. - Use
lpr_set_ros()
to assign these response labels in English, Spanish, or Portuguese.
π¨ Workflow: AmericasBarometer Data Visualization
-
Load the package in R:
-
Load LAPOP Lab fonts:
-
Apply the AmericasBarometer sampling design with:
lpr_data()
-
Choose the appropriate
lpr
graph type:- Histograms:
lpr_hist()
- Cross-country comparison:
lpr_cc()
- Time series:
lpr_ts()
- Breakdown by covariates:
lpr_mover()
- Histograms:
-
Store the output in an R object.
File names: .csv and graphics files should have the same name. Their names should be in the following standard format: CountryYear/ts_DVcode(s)_IVcode(s)_graphtype.filetype.
-
Examples:
- mex21_countfair1_hist.csv
- hnd_b4_ts.svg
- ab23_vic1ext_pais_cc.svg
There will be some cases that do not easily fit this standard. Use your best judgment.
-
Use the corresponding
lapop
plotting function to produce the visualization:- Examples:
lapop_hist()
,lapop_cc()
,lapop_ts()
, etc.
- Examples:
-
Export the figure to your machine with:
π€ Workflow: Contributing to the lapop
R Package
- Fork the repository and clone it to your local machine.
- Create a new branch for your feature or fix.
- Add your new function in the
R/
folder. - Document the function with roxygen2 comments.
- Run
devtools::document()
to generate.Rd
files inman/
and updateNAMESPACE
. - Commit your changes and push the branch to your fork.
- Submit a pull request to the main repository.