Type: | Package |
Title: | Simplifying 'ggplot2' for Survey Data |
Version: | 1.0.0 |
Author: | Brittany Alexander |
Maintainer: | Brittany Alexander <balexanderstatistics@gmail.com> |
Description: | Functions for survey data including svydesign objects from the 'survey' package that call 'ggplot2' to make bar charts, histograms, boxplots, and hexplots of survey data. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
Depends: | R (≥ 3.5.0), ggplot2, survey, hexbin, dplyr |
Imports: | stats |
RoxygenNote: | 7.1.2 |
NeedsCompilation: | no |
Packaged: | 2022-05-02 15:31:54 UTC; Brittany.Alexander |
Repository: | CRAN |
Date/Publication: | 2022-05-04 07:20:02 UTC |
Crosstabs of Two Variables
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes. This function creates a crosstab of x by a second variable y.
Usage
ggbarcrosstabs(df, x, y, weights, fill = NULL, labeller = NULL)
Arguments
df |
data frame of survey |
x |
variable to bar chart |
y |
faceting variable |
weights |
survey weights that sum to sample size |
fill |
if true the fill of each bar will be a different color corresponding to the level of the factor |
labeller |
argument to pass onto facet_grid |
Value
ggplot object
Examples
library(survey)
data(api)
ggbarcrosstabs(apistrat, stype, yr.rnd, pw)+ylab("Proportion")
ggbarcrosstabs(apistrat, stype, yr.rnd, pw, fill = TRUE)+ylab("Proportion")
data(nhanes)
ggbarcrosstabs(nhanes, race, agecat, WTMEC2YR)
Crosstabs of Three Variables
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
ggbarcrosstabs3d(df, x, y, z, weights, fill = NULL, labeller = NULL)
Arguments
df |
data frame |
x |
bar chart variable |
y |
crosstab variable 1 (horizontal facets) |
z |
crosstab variable 2 (vertical facets) |
weights |
survey weights that sum to sample size |
fill |
if true the fill of each bar will be a different color corresponding to the level of the factor |
labeller |
argument to pass onto facet_grid |
Value
ggplot pbject
Examples
library(survey)
data(api)
ggbarcrosstabs3d(apistrat, stype, yr.rnd, awards, pw)
ggbarcrosstabs3d(apistrat, stype, yr.rnd, awards, pw, TRUE)
data(nhanes)
ggbarcrosstabs3d(nhanes, race, agecat, RIAGENDR, WTMEC2YR)
Crosstabs of Three Variables Using svy.design object
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
ggbarcrosstabs3d_svy(surveyobj, x, y, z, fill = NULL, labeller = NULL)
Arguments
surveyobj |
svy.design obj |
x |
bar chart variable |
y |
crosstab variable 1 (horizontal facets) |
z |
crosstab variable 2 (vertical facets) |
fill |
if true the fill of each bar will be a different color corresponding to the level of the factor |
labeller |
argument to pass onto facet_grid |
Value
ggplot object
Examples
library(survey)
data(api)
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
ggbarcrosstabs3d_svy(dstrat, stype, yr.rnd, awards)
ggbarcrosstabs3d_svy(dstrat, stype, yr.rnd, awards, fill = TRUE)
data(nhanes)
design <- svydesign(id=~SDMVPSU, strata=~SDMVSTRA, weights=~WTMEC2YR, nest=TRUE,data=nhanes)
ggbarcrosstabs3d_svy(design, race, agecat, RIAGENDR)
Crosstabs for svy.design objects
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
ggbarcrosstabs_svy(surveyobj, x, y, fill = NULL, labeller = NULL)
Arguments
surveyobj |
svy.design obj |
x |
variable for bar chart |
y |
faceting variable (comparison factor) |
fill |
if true the fill of each bar will be a different color corresponding to the level of the factor |
labeller |
argument to pass onto facet_grid |
Value
ggplot object
Examples
library(survey)
library(ggplot2)
data(api)
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
ggbarcrosstabs_svy(dstrat, stype, yr.rnd)+ylab("Proportion")
ggbarcrosstabs_svy(dstrat, stype, yr.rnd, TRUE)+ylab("Proportion")
data(nhanes)
design <- svydesign(id=~SDMVPSU, strata=~SDMVSTRA, weights=~WTMEC2YR, nest=TRUE,data=nhanes)
ggbarcrosstabs_svy(design, race, agecat)
Weighted Univariate Bar Charts
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
ggbarweight(df, x, weights, fill = NULL)
Arguments
df |
data frame of survey |
x |
name of question of interest |
weights |
survey weights that sums to sample size |
fill |
if true the fill of each bar will be a different color corresponding to the level of the factor |
Value
ggplot object
Examples
library(survey)
#Example with data frame
data(api)
ggbarweight(apistrat, stype, pw)
ggbarweight(apistrat, stype, pw, fill = TRUE)
data(nhanes)
ggbarweight(nhanes, race, WTMEC2YR)+ylab("Proportion")
Bar Chart from svydesign objects
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
ggbarweight_svy(surveyobj, x, fill = NULL)
Arguments
surveyobj |
svydesign |
x |
variable to plot |
fill |
if true the fill of each bar will be a different color corresponding to the level of the factor |
Value
ggplot object
Examples
library(survey)
data(api)
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
ggbarweight_svy(dstrat, stype)+ylab("Proportion")
ggbarweight_svy(dstrat, stype, fill = TRUE)
data(nhanes)
design <- svydesign(id=~SDMVPSU, strata=~SDMVSTRA, weights=~WTMEC2YR, nest=TRUE,data=nhanes)
ggbarweight_svy(design, agecat)+ylab("Proportion")
ggbarweight_svy(design, agecat, fill = TRUE)+ylab("Proportion")
Weighted Box Plot of One Variable
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
ggboxweight(df, x, weights)
Arguments
df |
data frame |
x |
first variable of interest |
weights |
survey weights that sums to sample size |
Value
ggplot object
Examples
library(survey)
data(api)
ggboxweight(apistrat, api00, pw)
data(election)
ggboxweight(election_pps, Bush, p)
Weighted Boxplot with a categorical variable
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
ggboxweight2d(df, x, y, weights)
Arguments
df |
data frame |
x |
numeric variable of interest |
y |
categorical variable of interest |
weights |
survey weights that sums to sample size |
Value
ggplot object
Examples
library(survey)
data(api)
ggboxweight2d(apistrat, api00, stype, pw)
Weighted Boxplot of a survey object with a categorical variable
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
ggboxweight2d_svy(surveyobj, x, y)
Arguments
surveyobj |
svy.design object |
x |
variable to boxplot |
y |
categorical variable |
Value
ggplot object
Examples
library(survey)
data(api)
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
ggboxweight2d_svy(dstrat, api00, stype)
Weighted Boxplot with a categorical x axis and a faceting variable
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
ggboxweight3d(df, x, y, z, weights)
Arguments
df |
data frame |
x |
first categorical variable of interest |
y |
numeric variable of interest |
z |
second variable of interest for faceting |
weights |
survey weights that sums to sample size |
Value
ggplot object
Examples
library(survey)
data(api)
ggboxweight3d(apistrat, api00, stype,awards, pw)
Weighted Boxplot of svy.design object with two categorical variables
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
ggboxweight3d_svy(surveyobj, x, y, z)
Arguments
surveyobj |
svy.design |
x |
variable to boxplot |
y |
first categorical variable |
z |
second categorical variable (for faceting) |
Value
ggplot object
Examples
library(survey)
data(api)
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
ggboxweight3d_svy(dstrat, api00, stype, awards)
Weighted Box Plot of svy.design object
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
ggboxweight_svy(surveyobj, x)
Arguments
surveyobj |
svy.design object |
x |
variable to boxplot |
Value
ggplot object
Examples
library(survey)
data(api)
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
ggboxweight_svy(dstrat, api00)
Weighted Hex Plot
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
gghexweight(df, x, y, weights)
Arguments
df |
data frame |
x |
name of variable for x axis |
y |
name of variable for y axis |
weights |
name of weights variable |
Value
ggplot object
Examples
library(survey)
data(api)
gghexweight(apistrat, api99, api00, pw)
Weighted Hex Plot with One Facet Variable
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
gghexweight2d(df, x, y, z, weights)
Arguments
df |
data frame |
x |
name of variable for x axis |
y |
name of variable for y axis |
z |
faceting categorical variable |
weights |
name of weights variable |
Value
ggplot object
Examples
library(survey)
data(api)
gghexweight2d(apistrat, api99, api00, stype, pw)
Weighted Hex Plot of svy.design with One Facet Variable
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
gghexweight2d_svy(surveyobj, x, y, z)
Arguments
surveyobj |
svy.design |
x |
variable for x axis |
y |
variable for y axis |
z |
faceting variable |
Value
ggplot object
Examples
library(survey)
data(api)
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
gghexweight2d_svy(dstrat, api99, api00, stype)
Weighted Box Plot with Two Facet Variables
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
gghexweight3d(df, x, y, a, b, weights)
Arguments
df |
data frame |
x |
name of variable for x axis |
y |
name of variable for y axis |
a |
first faceting variable |
b |
second faceting variable |
weights |
name of weights variable |
Value
ggplot object
Examples
library(survey)
data(api)
gghexweight3d(apistrat, api99, api00, stype, awards, pw)
Weighted Hex Plot of svy.design with Two Faceting Variables
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
gghexweight3d_svy(surveyobj, x, y, a, b)
Arguments
surveyobj |
svy.design |
x |
variable for x axis |
y |
variable for y axis |
a |
horizontal facetting variable |
b |
vertical facetting variable |
Value
ggplot object
Examples
library(survey)
data(api)
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
gghexweight3d_svy(dstrat, api99, api00, stype, awards)
Weighted Hex Plot of Survey Design Object
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
gghexweight_svy(surveyobj, x, y)
Arguments
surveyobj |
svy.design |
x |
name of variable for x axis |
y |
name of variable for y axis |
Value
ggplot object
Examples
library(survey)
data(api)
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
gghexweight_svy(dstrat, api99, api00)
Weighted Histogram
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
gghistweight(df, x, weights, binwidth = NULL)
Arguments
df |
data frame |
x |
variable of interest |
weights |
survey weights that sum to sample size |
binwidth |
desired binwidth, if NULL bins in geom_histogram defaults to 30 |
Value
ggplot object
Examples
library(survey)
data(api)
gghistweight(apistrat, api00, pw)
gghistweight(apistrat, api00, pw, binwidth = 10)
data(election)
gghistweight(election_pps, Bush, p)
Weighted Histogram with One Facet In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Description
Weighted Histogram with One Facet In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
gghistweight2d(df, x, y, weights, binwidth = NULL)
Arguments
df |
data frame |
x |
first variable of interest |
y |
categorical variable for faceting |
weights |
survey weights that sum to sample size |
binwidth |
desired binwidth, if NULL bins in geom_histogram defaults to 30 |
Value
ggplot object
Examples
library(survey)
data(api)
gghistweight2d(apistrat, api00, stype, pw)
gghistweight2d(apistrat, api00, stype, pw, binwidth = 10)
Histogram of svy.object with One Facet
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
gghistweight2d_svy(surveyobj, x, y, binwidth = NULL)
Arguments
surveyobj |
svy.design object |
x |
variable to histogram |
y |
categorical variable to facet |
binwidth |
binwidth to pass to geom_hist |
Value
ggplot object
Examples
library(survey)
data(api)
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
gghistweight2d_svy(dstrat, api00, stype)
gghistweight2d_svy(dstrat, api00, stype, binwidth = 10)
Weighted Histogram with Two Facets
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
gghistweight3d(df, x, y, z, weights, binwidth = NULL)
Arguments
df |
data frame |
x |
first variable of interest |
y |
first categorical variable for faceting |
z |
second categorical variable for faceting |
weights |
survey weights that sum to sample size |
binwidth |
desired binwidth, if NULL bins in geom_histogram defaults to 30 |
Value
ggplot object
Examples
library(survey)
data(api)
gghistweight3d(apistrat, api00, stype, awards, pw)
gghistweight3d(apistrat, api00, stype, awards, pw, binwidth = 10)
Histogram of svy.design object with two facets
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
gghistweight3d_svy(surveyobj, x, y, z, binwidth = NULL)
Arguments
surveyobj |
svy.design object |
x |
variable to histogram |
y |
horizontal facet |
z |
vertical facet |
binwidth |
binwidth to pass to geom_hist |
Value
ggplot object
Examples
library(survey)
data(api)
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
gghistweight3d_svy(dstrat, api00, stype, awards)
gghistweight3d_svy(dstrat, api00, stype, awards, binwidth = 10)
Histogram of svgdesign object
Description
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
Usage
gghistweight_svy(surveyobj, x, binwidth = NULL)
Arguments
surveyobj |
svy.design object |
x |
variable to histogram |
binwidth |
binwidth to pass to geom_hist |
Value
ggplot object
Examples
library(survey)
data(api)
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
gghistweight_svy(dstrat, api00)
gghistweight_svy(dstrat, api00, binwidth = 10)