Learn R Programming

ggsurvey: A Package to Visualize Survey Data using ggplot2

This package is presently in early development. Functions are not fully documented but are functional. More examples and a vignette are coming. I appreciate any feedback. There will be an AAPOR 2022 Conference short course on this package. That course will assume only basic knowledge handling survey data in R.

This package builds upon ggplot2 but is designed for survey data with a goal of taking less code than using base ggplot2 by having a series of functions. It is designed with survey data that is weighted for differential non-response in mind. There has not been testing yet on more complex sample designs. But if you survey is one where you can calculate the mean with a simple weighted average these functions should work for you.

The base functions support data.frames as input and a class of functions for svy.design objects. All functions have an option for weights, if you do not have weights use ggplot2. The following geoms will be supported: geom_bar, geom_histogram, geom_boxplot, geom_hex. Options for 2d and 3d faceting exist for all functions. The geom_bar functions are design to make bar charts of histograms in crosstab style. The goal of this package is to simplify the syntax used to make plots of survey data.

Example Plot:

This package is currently located on github. Run the following code to install.

# install.packages("devtools")  #if devtools is not installed on your machine
devtools::install_github("balexanderstats/ggsurvey")

Future Functionality:

  1. Passing on various aestestics to the geom functions like color, fill, size.
  2. Adding functions for error bars on various graphs.

Known issues: None

Copy Link

Version

Install

install.packages('ggsurvey')

Monthly Downloads

235

Version

1.0.0

License

MIT + file LICENSE

Maintainer

Brittany Alexander

Last Published

May 4th, 2022

Functions in ggsurvey (1.0.0)

gghexweight3d_svy

Weighted Hex Plot of svy.design with Two Faceting Variables
gghexweight3d

Weighted Box Plot with Two Facet Variables
gghexweight2d_svy

Weighted Hex Plot of svy.design with One Facet Variable
gghistweight3d

Weighted Histogram with Two Facets
gghistweight2d

Weighted Histogram with One Facet In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
ggboxweight3d

Weighted Boxplot with a categorical x axis and a faceting variable
gghistweight2d_svy

Histogram of svy.object with One Facet
gghexweight2d

Weighted Hex Plot with One Facet Variable
gghistweight

Weighted Histogram
gghexweight

Weighted Hex Plot
gghistweight3d_svy

Histogram of svy.design object with two facets
gghexweight_svy

Weighted Hex Plot of Survey Design Object
gghistweight_svy

Histogram of svgdesign object
ggboxweight3d_svy

Weighted Boxplot of svy.design object with two categorical variables
ggboxweight_svy

Weighted Box Plot of svy.design object
ggbarcrosstabs_svy

Crosstabs for svy.design objects
ggbarweight

Weighted Univariate Bar Charts
ggboxweight

Weighted Box Plot of One Variable
ggbarcrosstabs3d

Crosstabs of Three Variables
ggbarweight_svy

Bar Chart from svydesign objects
ggbarcrosstabs

Crosstabs of Two Variables
ggbarcrosstabs3d_svy

Crosstabs of Three Variables Using svy.design object
ggboxweight2d

Weighted Boxplot with a categorical variable
ggboxweight2d_svy

Weighted Boxplot of a survey object with a categorical variable