plot_barplot: Plot (stacked) barplot with annotations

Description Usage Arguments Value Examples

View source: R/barplot.R

Description

This uses geom_bar, but it makes it easy to make both stacked and unstacked plots and adjust text annotations accordingly.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
plot_barplot(
  data,
  x,
  y,
  label = NULL,
  color = NULL,
  fill = NULL,
  stacked = TRUE,
  constant_height = TRUE,
  text_size = 3,
  facet_rows = c(),
  facet_columns = c(),
  facet_type = "grid",
  ...
)

Arguments

data

data frame containing dataset to use for plotting

x

column for x-axis

y

column for y-axis

label

column for text annotation

color

column for color

stacked

boolean whether result should be a stacked barplot or not

constant_height

boolean whether stacked bars should have constant height (proportions plotted)

facet_rows

columns for faceting by row

facet_columns

columns for faceting by column

facet_type

either "wrap" or "grid", corresponding to facet_wrap and facet_grid respectively

...

params to either facet_wrap or facet_grid

Value

ggplot object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
library(ggexp)
library(dplyr)

data = mtcars %>%
  mutate(cyl = factor(cyl)) %>%
  group_by(cyl, am) %>%
  tally()

plot_barplot(
  data = data,
  x = "am",
  y = "n",
  color = "cyl",
  label = "cyl"
)

keshavmot2/ggexp documentation built on Feb. 6, 2021, 1:38 a.m.