I have some questions about purrr::pmap to make multiple plots of ggplot in nested.data.frame.
I can run below code without problem by using purrr::map2 and I can make multiplots(2 plots) in nested.data.frame.
As a example, I used the iris dataset in 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)))
But, when I want to plot more than 2 plots, I can't solve using purrr::pmap like below code.
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, ~ ggplot(., aes(Sepal.Length, Petal.Length)) + geom_point())) %>%
mutate(g = purrr::pmap(gg1, gg2,gg3, ~ gridExtra::grid.arrange(.x, .y, .z)))
> Error in mutate_impl(.data, dots) : Index 1 is not a length 1 vector
Is there is a way of solving this problem in nested.data.frame ? Please give me some advices or answers.