Learn R Programming

tidyplots (version 0.2.1)

add_barstack_absolute: Add bar stack

Description

Add bar stack

Usage

add_barstack_absolute(plot, width = 0.8, reverse = FALSE, ...)

add_barstack_relative(plot, width = 0.8, reverse = FALSE, ...)

Value

A tidyplot object.

Arguments

plot

A tidyplot generated with the function tidyplot().

width

Width of the plot area. Defaults to 50.

reverse

Whether the order should be reversed or not. Defaults to FALSE, meaning not reversed.

...

Arguments passed on to the geom function.

Examples

Run this code
# for a `count` only provide `color`
# `count` of the data points in each `energy_type` category
energy %>%
  tidyplot(color = energy_type) %>%
  add_barstack_absolute()

energy %>%
  tidyplot(color = energy_type) %>%
  add_barstack_relative()

# for a `sum` provide `color` and `y`
# `sum` of `energy` in each `energy_type` category
energy %>%
  tidyplot(y = energy, color = energy_type) %>%
  add_barstack_absolute()

energy %>%
  tidyplot(y = energy, color = energy_type) %>%
  add_barstack_relative()

# Include variable on second axis
energy %>%
  tidyplot(x = year, y = energy, color = energy_type) %>%
  add_barstack_absolute()

energy %>%
  tidyplot(x = year, y = energy, color = energy_type) %>%
  add_barstack_relative()

# Flip x and y-axis
energy %>%
  tidyplot(x = energy, y = year, color = energy_type) %>%
  add_barstack_absolute(orientation = "y")

energy %>%
  tidyplot(x = energy, y = year, color = energy_type) %>%
  add_barstack_relative(orientation = "y")

Run the code above in your browser using DataLab