I'm using Rscript to run a plot as follows:
x=1:10
y=1:10
plot(x,y)
I expect this code to popup a window with a graphic showing the plot when I run the code like this:
Rscript plot.R
The program finishes to completion, and the graphic does not appear, not even momentarily. I know this code is right because it does produce a plot in the Rstudio GUI.
Does Rscript have a feature to popup that plot automatically on execution?
Getting started Start R by double-clicking on the R icon on the desktop, or by clicking on the R icon in the start menu. The R graphical user interface (GUI) will open, containing a single window called the command or console window.
Pop up the graphics window from Rscript, Example 1:
library(tcltk)
x=1:10
y=1:10
windows() #Use X11() or quartz() if on linux or mac.
plot(x,y)
prompt <- "hit spacebar to close plots"
extra <- "some extra comment"
capture <- tk_messageBox(message = prompt, detail = extra)
The above code presents the plot in a popup window and waits for you to press ok on the tk_messageBox dialog.
Pop up the graphics window from Rscript, Example 2:
png("mygraphic.png")
x = 1:10
print(x^2)
plot(x, x^2, 'o')
print("done")
dev.off()
browseURL("mygraphic.png")
The above code saves the png to disk as a file and asks the operating system to open the file in the program designed for that filetype.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With