小编Lc_*_*ecg的帖子

如何使用purrr :: pmap在nested.data.frame中绘制多个ggplot

我有一些关于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)

r ggplot2 purrr

15
推荐指数
1
解决办法
2256
查看次数

标签 统计

ggplot2 ×1

purrr ×1

r ×1