tbl_chart: Table for ggplot2 Charting

Description Usage Arguments Value Examples

View source: R/tbl_chart.R

Description

Creates a summarized data frame out of a raw dataframe ready for ggplot2 charting.

Usage

1
2
tbl_chart(df, x, subgroup, weight = NULL, nlabels = FALSE,
  newline = FALSE)

Arguments

df

A raw data frame that includes a subgroup variable, a variable to be tested, and optionally a weight variable.

x

A factor or numeric variable name to be charted, in quotes.

subgroup

A factor variable name that subgroups cases, in quotes.

weight

Optional. A post-stratification weight variable name, in quotes.

nlabels

A logical argument. Default is FALSE. If TRUE, the subgroup levels will be changed to include the unweighted sample sizes ("subgroup (n=xx)").

newline

A logical argument. Default is FALSE. If TRUE, the unweighted sample sizes will be shown on a separate line.

Value

A summary data frame ready for ggplot2 charting that provides each group's sample sizes and their proportions for each level of the variable (if the variable is a factor) or their means (if the variable is a numeric).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#Prepping the data first
gss_data1 <- dplyr::filter(gss_data, year == "2016",
                                      conlegis %in% c("A GREAT DEAL", "ONLY SOME", "HARDLY ANY"))

#Factor variable with weights
tbl_chart(gss_data1, "conlegis", "region", "wtssall")

#Factor variable without weights
tbl_chart(gss_data1, "conlegis", "region")

#Numeric variable with weights
tbl_chart(gss_data1, "coninc", "region", "wtssall")

#Numeric variable without weights
tbl_chart(gss_data1, "coninc", "region")

philstraforelli/ggsigmark documentation built on May 20, 2019, 1:59 p.m.