I have some questions about purrr :: pmap to make some ggplot plots in the nested.data.frame file.
I can run the code below without problems using purrr :: map2, and I can do multiple (2 graphics) in the nested.data.frame file.
As an example, I used the aperture 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 build more than 2 graphs, I cannot solve using purrr :: pmap, as shown below.
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 a way to solve this problem in the nested.data.frame file? Please give me some tips or answers.
r ggplot2 purrr
Lc_decg
source share