bars: Create Bar Charts

Description Usage Arguments Details Value Author(s) Examples

View source: R/bars.R

Description

Create a bar chart based on ggplot.

Usage

1
2
3
4
5
6
7
bars(data, count, group, highlight_variable = NA,
  ordered = "alphabetically", first_group = NA, flipped = TRUE,
  labelled = FALSE, show_percent = NA, label_nudge_y = -0.02 *
  max(select(data, {     {         count     } })), label_nudge_x = 0,
  label_size = 3, label_color = "white", label_hjust = "right",
  axis.title.x = element_blank(), axis.title.y = element_blank(),
  title = element_blank(), legend.position = "none", fontsize = 16)

Arguments

data

A data frame.

count

The variable that contains the number of observations per group.

group

The groups that are displayed as separate bars.

highlight_variable

Default NA, indicate variable that is TRUE only for the highlighted group.

ordered

Default alphabetically, alternative is count, then ordered in descending order.

first_group

Default NA, indicate a group which should be displayed first (left or top).

flipped

Default TRUE. If flipped is TRUE bars are horizontally (groups on y axis), otherwise bars are vertically (groups on x axis).

Details

Use ggplot's geom_col geom to create bar charts that are visually appealing and in line with a common theme and visualization style.

Value

A ggplot style bar graph.

Author(s)

Philipp Kollenda

Examples

1
2
3
4
## Not run: 
  bars(data = sdg %>% count(donor) %>% filter(n > 30000) %>% mutate(highlight = donor == "Germany"), count = n, group = donor, highlighted_var = highlight, ordered = "count", first_group = "Germany")
  
## End(Not run)

pkollenda/pkgraph documentation built on June 11, 2020, 8:40 p.m.