Created
June 29, 2022 16:58
-
-
Save brunaw/eb01253b0834be77d97fff55e3d4632a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(patchwork) | |
iris_species <- unique(iris$Species) | |
colours <- c("pink", "red", "blue") | |
plots <- purrr::map2( | |
iris_species, colours, | |
~{ | |
p <- iris |> | |
dplyr::filter(Species == .x) |> | |
ggplot(aes(x = Sepal.Width, y = Sepal.Length)) + | |
geom_point(colour = .y) + | |
ggtitle(paste0(.x)) | |
p | |
}) | |
# create a layout "automatically" | |
plot_code <- paste( | |
paste(paste0("plots[[", 1:length(plots), "]] +"), collapse = ""), | |
" plot_layout(ncol = 3)") | |
eval(str2lang(plot_code)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment