Apply a ggplot-function per group with dplyr and set title per group

后端 未结 3 2053
孤独总比滥情好
孤独总比滥情好 2020-12-01 06:25

I would like to create one separate plot per group in a data frame and include the group in the title.

With the iris dataset I can in base R and ggplot do this

3条回答
  •  孤街浪徒
    2020-12-01 07:10

    Use .$Species to pull the species data into ggtitle:

    iris %>% group_by(Species) %>% do(plots=ggplot(data=.) +
             aes(x=Petal.Width, y=Petal.Length) + geom_point() + ggtitle(unique(.$Species)))
    

提交回复
热议问题