Easily create a pyramid chart

pyramid_chart(
  data,
  x,
  y,
  group,
  bar_colors = c("#1F77B4", "#FF7F0E"),
  sort = "no",
  xlab = NULL,
  title = NULL
)

Arguments

data

Dataset to use for the pyramid chart

x

character or factor column of data

y

numeric column of data

group

character or factor column of data

bar_colors

character vector of length 2 containing colors

sort

character. Should the bars be sorted? By default "no".

xlab

character. X axis label

title

character. Plot title. By default no title is displayed.

Value

An object of class ggplot

Examples

data(popch) pyramid_chart(popch, age, pop, sex)
#> Warning: `expand_scale()` is deprecated; use `expansion()` instead.
#> Warning: `expand_scale()` is deprecated; use `expansion()` instead.
#> Warning: `expand_scale()` is deprecated; use `expansion()` instead.
#> Warning: `expand_scale()` is deprecated; use `expansion()` instead.
## Change bar colors pyramid_chart(popch, age, pop, sex, bar_colors = c("darkgreen", "darkorange"))
#> Warning: `expand_scale()` is deprecated; use `expansion()` instead.
#> Warning: `expand_scale()` is deprecated; use `expansion()` instead.
#> Warning: `expand_scale()` is deprecated; use `expansion()` instead.
#> Warning: `expand_scale()` is deprecated; use `expansion()` instead.
## Change x axis label and add title pyramid_chart(popch, age, pop, sex, xlab = "Population", title = "Switzerland 2020")
#> Warning: `expand_scale()` is deprecated; use `expansion()` instead.
#> Warning: `expand_scale()` is deprecated; use `expansion()` instead.
#> Warning: `expand_scale()` is deprecated; use `expansion()` instead.
#> Warning: `expand_scale()` is deprecated; use `expansion()` instead.