Title: | Simplifying `ggplot2` for Survey Data |
---|---|
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. |
Authors: | Brittany Alexander |
Maintainer: | Brittany Alexander <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.0 |
Built: | 2024-11-08 04:12:37 UTC |
Source: | https://github.com/balexanderstats/ggsurvey |
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.
ggbarcrosstabs(df, x, y, weights, fill = NULL, labeller = NULL)
ggbarcrosstabs(df, x, y, weights, fill = NULL, labeller = NULL)
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 |
ggplot object
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)
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)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
ggbarcrosstabs_svy(surveyobj, x, y, fill = NULL, labeller = NULL)
ggbarcrosstabs_svy(surveyobj, x, y, fill = NULL, labeller = NULL)
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 |
ggplot object
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)
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)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
ggbarcrosstabs3d(df, x, y, z, weights, fill = NULL, labeller = NULL)
ggbarcrosstabs3d(df, x, y, z, weights, fill = NULL, labeller = NULL)
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 |
ggplot pbject
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)
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)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
ggbarcrosstabs3d_svy(surveyobj, x, y, z, fill = NULL, labeller = NULL)
ggbarcrosstabs3d_svy(surveyobj, x, y, z, fill = NULL, labeller = NULL)
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 |
ggplot object
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)
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)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
ggbarweight(df, x, weights, fill = NULL)
ggbarweight(df, x, weights, fill = NULL)
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 |
ggplot object
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")
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")
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
ggbarweight_svy(surveyobj, x, fill = NULL)
ggbarweight_svy(surveyobj, x, fill = NULL)
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 |
ggplot object
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")
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")
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
ggboxweight(df, x, weights)
ggboxweight(df, x, weights)
df |
data frame |
x |
first variable of interest |
weights |
survey weights that sums to sample size |
ggplot object
library(survey) data(api) ggboxweight(apistrat, api00, pw) data(election) ggboxweight(election_pps, Bush, p)
library(survey) data(api) ggboxweight(apistrat, api00, pw) data(election) ggboxweight(election_pps, Bush, p)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
ggboxweight_svy(surveyobj, x)
ggboxweight_svy(surveyobj, x)
surveyobj |
svy.design object |
x |
variable to boxplot |
ggplot object
library(survey) data(api) dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc) ggboxweight_svy(dstrat, api00)
library(survey) data(api) dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc) ggboxweight_svy(dstrat, api00)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
ggboxweight2d(df, x, y, weights)
ggboxweight2d(df, x, y, weights)
df |
data frame |
x |
numeric variable of interest |
y |
categorical variable of interest |
weights |
survey weights that sums to sample size |
ggplot object
library(survey) data(api) ggboxweight2d(apistrat, api00, stype, pw)
library(survey) data(api) ggboxweight2d(apistrat, api00, stype, pw)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
ggboxweight2d_svy(surveyobj, x, y)
ggboxweight2d_svy(surveyobj, x, y)
surveyobj |
svy.design object |
x |
variable to boxplot |
y |
categorical variable |
ggplot object
library(survey) data(api) dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc) ggboxweight2d_svy(dstrat, api00, stype)
library(survey) data(api) dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc) ggboxweight2d_svy(dstrat, api00, stype)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
ggboxweight3d(df, x, y, z, weights)
ggboxweight3d(df, x, y, z, weights)
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 |
ggplot object
library(survey) data(api) ggboxweight3d(apistrat, api00, stype,awards, pw)
library(survey) data(api) ggboxweight3d(apistrat, api00, stype,awards, pw)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
ggboxweight3d_svy(surveyobj, x, y, z)
ggboxweight3d_svy(surveyobj, x, y, z)
surveyobj |
svy.design |
x |
variable to boxplot |
y |
first categorical variable |
z |
second categorical variable (for faceting) |
ggplot object
library(survey) data(api) dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc) ggboxweight3d_svy(dstrat, api00, stype, awards)
library(survey) data(api) dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc) ggboxweight3d_svy(dstrat, api00, stype, awards)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
gghexweight(df, x, y, weights)
gghexweight(df, x, y, weights)
df |
data frame |
x |
name of variable for x axis |
y |
name of variable for y axis |
weights |
name of weights variable |
ggplot object
library(survey) data(api) gghexweight(apistrat, api99, api00, pw)
library(survey) data(api) gghexweight(apistrat, api99, api00, pw)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
gghexweight_svy(surveyobj, x, y)
gghexweight_svy(surveyobj, x, y)
surveyobj |
svy.design |
x |
name of variable for x axis |
y |
name of variable for y axis |
ggplot object
library(survey) data(api) dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc) gghexweight_svy(dstrat, api99, api00)
library(survey) data(api) dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc) gghexweight_svy(dstrat, api99, api00)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
gghexweight2d(df, x, y, z, weights)
gghexweight2d(df, x, y, z, weights)
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 |
ggplot object
library(survey) data(api) gghexweight2d(apistrat, api99, api00, stype, pw)
library(survey) data(api) gghexweight2d(apistrat, api99, api00, stype, pw)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
gghexweight2d_svy(surveyobj, x, y, z)
gghexweight2d_svy(surveyobj, x, y, z)
surveyobj |
svy.design |
x |
variable for x axis |
y |
variable for y axis |
z |
faceting variable |
ggplot object
library(survey) data(api) dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc) gghexweight2d_svy(dstrat, api99, api00, stype)
library(survey) data(api) dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc) gghexweight2d_svy(dstrat, api99, api00, stype)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
gghexweight3d(df, x, y, a, b, weights)
gghexweight3d(df, x, y, a, b, weights)
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 |
ggplot object
library(survey) data(api) gghexweight3d(apistrat, api99, api00, stype, awards, pw)
library(survey) data(api) gghexweight3d(apistrat, api99, api00, stype, awards, pw)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
gghexweight3d_svy(surveyobj, x, y, a, b)
gghexweight3d_svy(surveyobj, x, y, a, b)
surveyobj |
svy.design |
x |
variable for x axis |
y |
variable for y axis |
a |
horizontal facetting variable |
b |
vertical facetting variable |
ggplot object
library(survey) data(api) dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc) gghexweight3d_svy(dstrat, api99, api00, stype, awards)
library(survey) data(api) dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc) gghexweight3d_svy(dstrat, api99, api00, stype, awards)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
gghistweight(df, x, weights, binwidth = NULL)
gghistweight(df, x, weights, binwidth = NULL)
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 |
ggplot object
library(survey) data(api) gghistweight(apistrat, api00, pw) gghistweight(apistrat, api00, pw, binwidth = 10) data(election) gghistweight(election_pps, Bush, p)
library(survey) data(api) gghistweight(apistrat, api00, pw) gghistweight(apistrat, api00, pw, binwidth = 10) data(election) gghistweight(election_pps, Bush, p)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
gghistweight_svy(surveyobj, x, binwidth = NULL)
gghistweight_svy(surveyobj, x, binwidth = NULL)
surveyobj |
svy.design object |
x |
variable to histogram |
binwidth |
binwidth to pass to geom_hist |
ggplot object
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)
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)
Weighted Histogram with One Facet In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
gghistweight2d(df, x, y, weights, binwidth = NULL)
gghistweight2d(df, x, y, weights, binwidth = NULL)
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 |
ggplot object
library(survey) data(api) gghistweight2d(apistrat, api00, stype, pw) gghistweight2d(apistrat, api00, stype, pw, binwidth = 10)
library(survey) data(api) gghistweight2d(apistrat, api00, stype, pw) gghistweight2d(apistrat, api00, stype, pw, binwidth = 10)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
gghistweight2d_svy(surveyobj, x, y, binwidth = NULL)
gghistweight2d_svy(surveyobj, x, y, binwidth = NULL)
surveyobj |
svy.design object |
x |
variable to histogram |
y |
categorical variable to facet |
binwidth |
binwidth to pass to geom_hist |
ggplot object
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)
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)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
gghistweight3d(df, x, y, z, weights, binwidth = NULL)
gghistweight3d(df, x, y, z, weights, binwidth = NULL)
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 |
ggplot object
library(survey) data(api) gghistweight3d(apistrat, api00, stype, awards, pw) gghistweight3d(apistrat, api00, stype, awards, pw, binwidth = 10)
library(survey) data(api) gghistweight3d(apistrat, api00, stype, awards, pw) gghistweight3d(apistrat, api00, stype, awards, pw, binwidth = 10)
In ggsurvey you specify both the plotting variables and weights in plain text with no quotes.
gghistweight3d_svy(surveyobj, x, y, z, binwidth = NULL)
gghistweight3d_svy(surveyobj, x, y, z, binwidth = NULL)
surveyobj |
svy.design object |
x |
variable to histogram |
y |
horizontal facet |
z |
vertical facet |
binwidth |
binwidth to pass to geom_hist |
ggplot object
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)
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)