ggplot2でグループごとの図を出力する
ggplotでグループごとに図を出力したい場合がある。 意外と簡単な方法でできるのでメモ。
library(ggplot2) library(dplyr)
res <- iris %>% group_by(Species) %>% do( plots= ggplot(data=.) + geom_point(aes(Sepal.Length, Petal.Length)) + ggtitle(.$Species) )
res
Species <fctr> plots <list> 1 setosa <S3: gg> 2 versicolor <S3: gg> 3 virginica <S3: gg>
res[[2]]