Explore categorical columns with bar charts

Author

Francisco Zambrano

Published

July 1, 2023

Installation

Development version from GitHub:

GitHub: https://github.com/zpio/ggexplorer

Show/Hide code
remotes::install_github("zpio/ggexplorer")
Show/Hide code
library(ggexplorer)

Examples

Diamonds dataset

Show/Hide code
ggplot2::diamonds

Basic Chart

Show/Hide code
plotBar(ggplot2::diamonds)

Fill

Show/Hide code
plotBar(ggplot2::diamonds, fill = "steelblue")

Pct

Show/Hide code
plotBar(ggplot2::diamonds, pct = TRUE)

Top

Show/Hide code
plotBar(ggplot2::diamonds, fill = "steelblue", top = 3)

Number of facet columns

Show/Hide code
plotBar(ggplot2::diamonds, fill = "steelblue", top = 5, ncol = 2)

Fill by

Show/Hide code
plotBar(ggplot2::diamonds, fill_var = cut)

Legend Position

Show/Hide code
plotBar(ggplot2::diamonds, fill_var = cut, legend_position = "bottom")

Position

Show/Hide code
plotBar(ggplot2::diamonds, fill_var = cut, position = "stack")

Show/Hide code
plotBar(ggplot2::diamonds, fill_var = cut, position = "dodge")

Show/Hide code
plotBar(ggplot2::diamonds, fill_var = cut, position = "fill")

Colour scales

Show/Hide code
plotBar(ggplot2::diamonds, fill_var = cut) +
  ggplot2::scale_fill_hue()

Interactive

Show/Hide code
plotBar(ggplot2::diamonds, fill_var = cut, position = "stack",
        interactive = TRUE)