bind_each_all: Bind each all.

View source: R/bind_each_all.R

bind_each_allR Documentation

Bind each all.

Description

Binds data to support plotting each category and all combined data.

Usage

bind_each_all(
  data,
  ...,
  name = "each_all",
  each = "Each",
  all = "All",
  all_after = Inf
)

Arguments

data

A data frame or tibble.

...

An unquoted variable.

name

A variable name. Defaults to each_all.

each

A string for the each value. Defaults to "Each".

all

A string for the all value. Defaults to "All".

all_after

A number for where the all value should be placed after. Use 0 for first or Inf for last. Defaults to Inf.

Value

A data frame or tibble

Examples

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

set_blanket()

penguins |>
  count(species)

penguins |>
  bind_each_all(species) |>
  count(species, each_all)

penguins |>
  bind_each_all(species) |>
  gg_jitter(
    x = species,
    y = body_mass_g,
  )

penguins |>
  bind_each_all(species) |>
  gg_jitter(
    x = species,
    y = body_mass_g,
    col = each_all,
    col_palette = c(blue, grey),
  ) +
  theme(legend.position = "none")

penguins |>
  bind_each_all(species) |>
  group_by(species, each_all) |>
  summarise(across(body_mass_g, \(x) mean(x, na.rm = TRUE))) |>
  gg_col(
    x = species,
    y = body_mass_g,
    col = each_all,
    col_palette = c(blue, grey),
    width = 0.5,
    y_label = "Average body mass g",
  ) +
  theme(legend.position = "none")

penguins |>
  bind_each_all(species, all = "All\nspecies") |>
  gg_jitter(
    x = species,
    y = body_mass_g,
    col = each_all,
    col_palette = c(blue, grey),
    facet = each_all,
    facet_layout = "grid",
    facet_scales = "free_x",
    facet_space = "free_x",
  ) +
  theme(legend.position = "none") +
  theme(strip.text.x = element_blank()) +
  labs(x = NULL)


davidhodge931/ggblanket documentation built on July 3, 2025, 9:53 p.m.