[R] Executing an R script and show the plots.

Anindya Mozumdar r@dmuzom @end|ng |rom out|ook@com
Sun Jan 26 17:30:41 CET 2020


Dear Felix,

> I would like to run R scripts like that: R -f script.r and still get the
> plots that pop up.

Since you are using ggplot2, you can use the ggsave function from the package to save the plot to a location of your choice. I tested the following script from the command line and it worked.

library(ggplot2)                                                                                                                                                                          
data("midwest",
     package="ggplot2")                                                                                                                                                        
ggplot(midwest, aes(x=area, y=poptotal)) + geom_point()
ggsave(paste0(getwd(), "/midwest.png"), device = "png")

Regards,
Anindya




More information about the R-help mailing list