Save ggplot within a function

前端 未结 2 636
清酒与你
清酒与你 2020-12-03 02:22

I\'m trying to save a ggplot within a function using graphics devices. But I found the code produces empty graphs. Below is a very very simple example.

libr         


        
2条回答
  •  再見小時候
    2020-12-03 03:15

    These plots have to be printed:

    ff <- function(){
      jpeg("a.jpg")
      p <- qplot(1:20, 1:20)
      print(p)
      dev.off()
    }
    ff()
    

    This is a very common mistake.

提交回复
热议问题