首页 > 解决方案 > 使用 twiddle 生成绘图(内联匿名函数)

问题描述

我正在尝试编写一个管道来根据attrition数据为每个部门创建一个年龄直方图。我想通过twiddle使用内联匿名函数map()

我尝试了以下方法,但坚持到底如何从中生成直方图。

attrition %>%
  nest(data = Department) %>%
  mutate(gg = map(data, ~ .x + theme(text = element_text(color = 'blue')))) %>%
  pull(gg)

标签: rpurrr

解决方案


用作mtcars示例:

library(tidyverse)

mtcars %>%
  nest(data = -cyl)  %>%
  mutate(gg = map(data, ~ ggplot(.x) + aes(mpg) + geom_histogram())) %>%
  pull(gg)

这将为您提供地块列表。


推荐阅读