Status Quo
library(tidyverse)
ggmultivar <- function(data, multi_vars){
prepped <- data %>%
pivot_longer(cols = {{multi_vars}})
ggplot(data = prepped) +
facet_wrap(~ name, scales = "free")
}
ggmultivar(palmerpenguins::penguins,
multi_vars = c(bill_length_mm, bill_depth_mm,
flipper_length_mm, body_mass_g))
last_plot() +
aes(x = value) +
geom_histogram(position = "identity") +
geom_rug(aes(color = species)) +
aes(fill = species) +
aes(alpha = species == "Chinstrap") +
scale_alpha_discrete(range = c(.3, .95))
## Warning: Using alpha for a discrete variable is not advised.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 8 rows containing non-finite outside the scale range
## (`stat_bin()`).
last_plot() +
facet_grid(sex ~ name, scales = "free")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 8 rows containing non-finite outside the scale range
## (`stat_bin()`).
ggmultivar(palmerpenguins::penguins %>% remove_missing(),
multi_vars = c(bill_length_mm, bill_depth_mm,
flipper_length_mm, body_mass_g)) +
aes(y = value, x = sex) +
geom_boxplot()
## Warning: Removed 11 rows containing missing values or values outside the scale
## range.
last_plot() +
aes(color = species)
palmerpenguins::penguins |>
select(c(1, 3:6)) %>%
pivot_longer(cols = 2:5) %>%
ggplot() +
aes(x = value) +
geom_histogram(alpha = .8) +
facet_wrap(~name, scales = "free_x") +
aes(fill = species)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 8 rows containing non-finite outside the scale range
## (`stat_bin()`).