Has anyone used any of the packages that deal with multiple ggplots together with the purr - nested dataframe workflow? Here I post a reprex of a ggplot for each species in the iris
dataset. And the desired output hardcoded with the patchwork
package. The goal is to add a %>%
that filters the species that I want the plots from and use them in a multiple plot
library(reprex)
library(tidyverse)
#> Warning: package 'tibble' was built under R version 3.5.2
library (patchwork)
iris %>%
rowid_to_column(var = "specimen") %>%
# gather(contains("."), key = "Measurement", value = "cm") %>%
group_by(Species) %>%
nest %>%
mutate(plot = map2(Species, data, function (.x,.y){
ggplot(data = .y, aes(x = Sepal.Length, y = Sepal.Width)) +
geom_smooth() +
ggtitle(label = .x)
})) -> iris.with.plots
iris.with.plots$plot[[1]] + iris.with.plots$plot[[2]]
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'
Created on 2019-01-22 by the reprex package (v0.2.1)