2

I use facet_wrap to every group plot, but I need to save every plot individual and find the under link.

I tried program the answer in the URL link and can save PDFfile, but present the ERROR MASSAGE.

CODE:

iris %>% group_by(Species) %>% 
  do({
    p <- ggplot(., aes(x =Sepal.Length, y = Petal.Length)) + geom_point()
    ggsave(p, filename = paste0("fig/", unique(.$Species), ".pdf"))
  })

ERROR MESSAGE:

Results are not data frames at positions: 1, 2, 3

URL: applying a function to the output of dplyr's group_by

Community
  • 1
  • 1
ogw
  • 353
  • 1
  • 2
  • 13
  • `do` wants you to return a data.frame – baptiste Nov 14 '16 at 07:50
  • 3
    Maybe you want `library(tidyverse);iris %>% split(.$Species) %>% map(~ggplot(., aes(x =Sepal.Length, y = Petal.Length)) + geom_point() ) %>% walk2(names(.), ~ggsave(.x, filename = paste0(.y, ".pdf")))` – lukeA Nov 14 '16 at 08:59

1 Answers1

3

we can make do have a point (or just any data.frame for that matter)

iris %>% group_by(Species) %>% 
  do({
    p <- ggplot(., aes(x =Sepal.Length, y = Petal.Length)) + geom_point()
    ggsave(p, filename = paste0("fig", unique(.$Species), ".pdf"))
    invisible(.)
  })
baptiste
  • 75,767
  • 19
  • 198
  • 294