Felix, I suggest you consider using an IDE such as RStudio as you develop and run R code. An integrated development environment will allow you to concentrate on learning R rather on the mechanics of running R in a non-standard environment. John
John David Sorkin M.D., Ph.D. Professor of Medicine Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine Baltimore VA Medical Center 10 North Greene Street<x-apple-data-detectors://12> GRECC<x-apple-data-detectors://12> (BT/18/GR) Baltimore, MD 21201-1524<x-apple-data-detectors://13/0> (Phone) 410-605-711<tel:410-605-7119>9 (Fax) 410-605-7913<tel:410-605-7913> (Please call phone number above prior to faxing) On Jan 26, 2020, at 3:20 PM, David Winsemius <dwinsem...@comcast.net> wrote: 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: windows.options, 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. -- David. 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=02%7C01%7CJSorkin%40som.umaryland.edu%7Cff399da2c92c46d8dbef08d7a29d28e1%7C717009a620de461a88940312a395cac9%7C0%7C0%7C637156668200832250&sdata=%2F4npPPdmZiflpvoByexxwJKfkSQmGASQimaxnnDyOj0%3D&reserved=0 PLEASE do read the posting guide https://nam03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.R-project.org%2Fposting-guide.html&data=02%7C01%7CJSorkin%40som.umaryland.edu%7Cff399da2c92c46d8dbef08d7a29d28e1%7C717009a620de461a88940312a395cac9%7C0%7C0%7C637156668200832250&sdata=Z%2FbUl0zEHpfVuQsvFysOAFps0VjeAtA7NdcL3VYJcus%3D&reserved=0 and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=02%7C01%7CJSorkin%40som.umaryland.edu%7Cff399da2c92c46d8dbef08d7a29d28e1%7C717009a620de461a88940312a395cac9%7C0%7C0%7C637156668200842231&sdata=VMdvcvmZ6Cn8kZ%2Buta44UT08Q5T%2FEf3X8ufWmYz9avE%3D&reserved=0 PLEASE do read the posting guide https://nam03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.R-project.org%2Fposting-guide.html&data=02%7C01%7CJSorkin%40som.umaryland.edu%7Cff399da2c92c46d8dbef08d7a29d28e1%7C717009a620de461a88940312a395cac9%7C0%7C0%7C637156668200842231&sdata=0%2BBjKhdtQ7cMP6wuDm36%2BJmLLWAMLHCDHtJ8ugl2oag%3D&reserved=0 and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] ______________________________________________ R-help@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.