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 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
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.fieldsattribute. - 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.tableattribute. - 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’ design effects with:
lpr_data() -
Choose the appropriate
lprgraph 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.extension.
-
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
lapopplotting 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.Rdfiles inman/and updateNAMESPACE. - Commit your changes and push the branch to your fork.
- Submit a pull request to the main repository.
- If you find a bug, please consider contributing to the lapop package — we spent all our money on coffee and data cleaning.