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

David Winsemius dw|n@em|u@ @end|ng |rom comc@@t@net
Sun Jan 26 21:20:03 CET 2020

You need to understand that the R interpreter does not have an 
interactive plot device when run as a script from an OS command line. 
You need to open an output device, `print` the output of the ggplot 
call, and then  _after_ closing the device appropriately, open the 
output in an appropriate viewer supplied by your unstated OS.

?Devices # brings up a list of possible devices and has a "See Also" 
section that says:


The individual help files for further information on any of the devices 
listed here;

on Windows:

on a Unix-alike:
X11.options, quartz.options,

ps.options and pdf.options for how to customize devices.

dev.interactive, dev.cur, dev.print, graphics.off, image, dev2bitmap.

On Unix-alikes only:
capabilities to see if X11, jpeg, png, tiff, quartz and the cairo-based 
devices are available.

So do some further reading to educate yourself.



On 1/24/20 8:32 AM, Felix Blind wrote:
> Dear R users,
> i am a python user trying to get my statistical knowledge up to speed
> and R is the language for that.
> I would like to run R scripts like that: R -f script.r and still get the
> plots that pop up.
> When I type the following code in the R REPL I get a nice plot:
> library(ggplot2)
> data("midwest",
> package="ggplot2")
> ggplot(midwest, aes(x=area, y=poptotal)) + geom_point()
> But when I put the same code in a file script.r and run it with R -f
> script.r or if I source it in the REPL with source("script.r") I do not
> get any plots shown.
> Can you guys tell me what I do wrong. (Apart from either using RStudio
> or the REPL exclusively)
> Kind regards,
> Felix
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list