我有一些关于purrr :: pmap的问题,可以在nested.data.frame中制作多个ggplot图.
我可以通过使用purrr :: map2在代码下运行而没有问题,我可以在nested.data.frame中创建多个图(2个图).
作为一个例子,我在R中使用了虹膜数据集.
library(tidyverse)
iris0 <- iris
iris0 <-
iris0 %>%
group_by(Species) %>%
nest() %>%
mutate(gg1 = purrr::map(data, ~ ggplot(., aes(Sepal.Length, Sepal.Width)) + geom_point())) %>%
mutate(gg2 = purrr::map(data, ~ ggplot(., aes(Sepal.Length, Petal.Width)) + geom_point())) %>%
mutate(g = purrr::map2(gg1, gg2, ~ gridExtra::grid.arrange(.x, .y)))
Run Code Online (Sandbox Code Playgroud)
但是,当我想绘制超过2个图时,我无法解决使用purrr :: pmap,如下面的代码.
iris0 <-
iris0 %>%
group_by(Species) %>%
nest() %>%
mutate(gg1 = purrr::map(data, ~ ggplot(., aes(Sepal.Length, Sepal.Width)) + geom_point())) %>%
mutate(gg2 = purrr::map(data, ~ ggplot(., aes(Sepal.Length, Petal.Width)) + geom_point())) %>%
mutate(gg3 = purrr::map(data, …
Run Code Online (Sandbox Code Playgroud)