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

后端 未结 3 2044
孤独总比滥情好
孤独总比滥情好 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:01

    This is another option using rowwise:

    plots2 = iris %>% 
        group_by(Species) %>% 
        do(plots = p %+% .) %>% 
        rowwise() %>%
        do(x=.$plots + ggtitle(.$Species))
    

提交回复
热议问题