scale_pct: Axis scales and formatting for percentages

scale_continuousR Documentation

Axis scales and formatting for percentages

Description

Wrappers around 'ggplot2::scale_x_continuous' and 'ggplot2::scale_y_continuous' to make it easy to format percentages.

Usage

scale_x_pct(..., limits = c(0, 1), labels = scales::percent)

scale_y_pct(..., limits = c(0, 1), labels = scales::percent)

Arguments

...

Arguments to 'ggplot2::scale_x_continuous' and 'ggplot2::scale_x_continuous'

limits

default is 'c(0, 1)' See '?ggplot2::scale_x_continuous' for additional details

labels

default is 'scales::percent' See '?ggplot2::scale_x_continuous' for additional details

References

https://github.com/thomas-neitmann/scalesextra

Examples

library(dplyr)
library(ggplot2)
library(palmerpenguins)

penguins %>%
  dplyr::count(species) %>%
  mutate(pct = n / sum(n)) %>%
  ggplot(data = .,
         aes(x = species,
             y = pct)) +
  geom_bar(stat = "identity")

penguins %>%
  dplyr::count(species) %>%
  mutate(pct = n / sum(n)) %>%
  ggplot(data = .,
         aes(x = species,
             y = pct)) +
  geom_bar(stat = "identity") +
  scale_y_pct()


emilelatour/laviz documentation built on Oct. 15, 2023, 1:41 p.m.