library(ggplot2)
library(dplyr)
library(palmerpenguins)
penguins <- penguins %>% tidyr::drop_na()
my_plot <- function(x_var) {
p <- penguins %>%
ggplot(aes(x = {{ x_var }})) +
geom_histogram()
x_var_name <- dplyr::quo_name(enquo(x_var))
ggsave(
filename = stringr::str_glue("{x_var_name}.png"),
plot = p
)
}
penguins %>%
select(ends_with("_mm")) %>%
purrr::map(my_plot)
#> Error in `expr_name()`:
#> ! `expr` must be a symbol, scalar, or call.
#> Backtrace:
#> ▆
#> 1. ├─penguins %>% select(ends_with("_mm")) %>% ...
#> 2. └─purrr::map(., my_plot)
#> 3. └─global .f(.x[[i]], ...)
#> 4. └─dplyr::quo_name(enquo(x_var))
#> 5. └─rlang::expr_name(quo_squash(quo))
#> 6. └─rlang::abort(...)
Created on 2022-09-22 with reprex v2.0.2
I don't know how to write it. Can you give me some help? thanks