View source: R/bind_each_all.R
bind_each_all | R Documentation |
Binds data to support plotting each category and all combined data.
bind_each_all(
data,
...,
name = "each_all",
each = "Each",
all = "All",
all_after = Inf
)
data |
A data frame or tibble. |
... |
An unquoted variable. |
name |
A variable name. Defaults to |
each |
A string for the each value. Defaults to |
all |
A string for the all value. Defaults to |
all_after |
A number for where the all value should be placed after. Use |
A data frame or tibble
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.