Create a gt table with values compared by name, geography, or other grouping variable
Source:R/gt_acs_compare.R
gt_acs_compare.Rdgt_acs_compare() is a variant of gt_acs() designed to support the
comparison of multiple named areas or multiple geographies side-by-side in a
combined gt table. This function only works if the arrangement of rows is
the same for each group and all groups have the same number of rows.
Usage
gt_acs_compare(
data,
.by = name_col,
name_col = "NAME",
value_cols = c("estimate", "moe"),
perc_value_cols = c("perc_estimate", "perc_moe"),
column_title_col = "column_title",
variable_col = "variable",
drop_cols = c(name_col, variable_col, "GEOID"),
value_col_label = "Est.",
perc_value_col_label = "% share",
decimals = 0,
return_gt = TRUE,
...
)Arguments
- data
Input data table
obj:<data.frame>|obj:<tbl_df>// requiredA
data.frameobject or a tibble (tbl_df).- .by
Name of grouping column. Defaults to
name_col- name_col
Name column. Defaults to "NAME". Dropped from table by default.
- variable_col
Variable column name. Defaults to "variable". Dropped from table by default.
- drop_cols
Columns to drop before creating gt table. Defaults to
c(name_col, variable_col, "GEOID")- value_col_label, perc_value_col_label
Labels for value/estimate column and percent value/estimate column. Not yet implemented as an option.
- return_gt
If
TRUE(default), return a formatted gt table. IfFALSE, return the data frame for a comparison table.- ...
Arguments passed on to
gt_acscombined_spannerIf not
NULL, combined_spanner is passed to label parameter ofgt::tab_spanner()using both est_cols and perc_cols as the columns parameter.column_title_col,column_title_labelColumn title and label. If column_title_label is a string, column_title_col is required. column_title_label can also be a named vector in the format of
c("label" = "column"). column_title_col defaults to "column_title"name_col,name_col_labelPlace name column and label. name_col_label can be a string or a named vector (similar to column_title_label). name_col defaults to "NAME"
hide_na_colsIf
TRUE(default), hide columns where all values areNA.drop_geometryIf
TRUE(default) and data is an sf object, drop geometry before turning the data frame into a table.rownames_to_stubUse data frame row labels in the stub
scalar<logical>// default:FALSEAn option to take rownames from the input
datatable (should they be available) as row labels in the display table stub.row_group_as_columnMode for displaying row group labels in the stub
scalar<logical>// default:FALSEAn option that alters the display of row group labels. By default this is
FALSEand row group labels will appear in dedicated rows above their respective groups of rows. IfTRUErow group labels will occupy a secondary column in the table stub.append_noteIf
TRUE, add source_note to the end of the generated ACS data label. IfFALSE, any supplied source_note will be used instead of an ACS label.source_noteSource note text
scalar<character>// requiredText to be used in the source note. We can optionally use the
md()andhtml()functions to style the text as Markdown or to retain HTML elements in the text.surveyACS survey, "acs5", "acs3", or "acs1".
yearBased on the year and survey,
acs_survey_ts()returns a vector of years for non-overlapping ACS samples to allow comparison.prefixText to insert before ACS survey label.
tableOne or more table IDs to include in label or source note.
endA character string appended to the end of the full label. Defaults to ".".