bar_chart_counts: Bar chart of counts with TNTP polish

Description Usage Arguments Examples

View source: R/bar_chart_counts.R

Description

Takes a user supplied data frame and turns the designated column into an N bar chart (uses position dodge from ggplot2).

Usage

1
2
3
bar_chart_counts(df, var, group_var, labels = "n",
  var_color = "medium_blue", group_colors, title = NULL, var_label,
  digits = 1, font = "Segoe UI", font_size = 12)

Arguments

df

the data.frame to be used in the bar chart

var

unquoted column name for variable to count

group_var

(optional) unquoted column name for group variable. If this is specified, you get a 2-variable clustered bar chart. If left blank, a single variable bar chart.

labels

should labels show the count ("n") or the percentage ("pct")?

var_color

color for non-grouped charts; set to medium_blue by default. For both this and group_colors, strings will be tried in palette_tntp automatically. So c("orange", "dark_blue") will get you the official TNTP colors, while c("orange", "blue") will get you TNTP orange but generic blue.

group_colors

character vector of group colors, if a specific palette is desired

title

main chart title

var_label

label for x-axis

digits

integer indicating the number of decimal places to be used in percentages. In truncating, ties are rounded up, like in MS Excel, i.e., 10.5 and 11.5 become 11 and 12. This is *not* base R's default behavior.

font

font for chart text; Segoe UI by default

font_size

size for chart text; set to 12 by default

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# all examples not run b/c of Travis CI failures
# failure due to not having Segoe UI font imported
# library(dplyr) # for %>% pipe
# # An N bar chart by default
# mtcars %>%
#   bar_chart_counts(var     = cyl,
#                    title   = "Number of mtcars by cylinder")
#
# # Use a grouping variable
# mtcars %>%
#   bar_chart_counts(var          = cyl,
#                    group_var    = vs,
#                    labels        = "pct",
#                    title        = "Percentage of V vs. Straight engines by # of cylinders")
#
# # Change default color
# mtcars %>%
#   bar_chart_counts(var       = cyl,
#                    var_color = "orange",
#                    title     = "Number of mtcars by cylinder")
# # Specify color by group
#   bar_chart_counts(mtcars, am, cyl, group_colors = c("orange", "green", "dark_blue"), labels = "pct")

tntp/tntpr documentation built on Aug. 11, 2019, 4:52 a.m.