0

I am using Xterm on a linux server so I can quickly plot data without transferring the files to my local machine. I have a R script that uses ggplot(), not inside a function. When I open R through Xterm I use these commands to run the script and the plot windows works fine in Xterm

commandArgs <- function(...) 'plotname'
source('graph.r', print.eval=TRUE))

However when I try from bash with Rscript, such as

Rscript graph.r plotname

The script runs but the plot window doesn't open. I know this is a ggplot problem because if I just use plot() inside the script the plot window works. I have tried several suggestions from this question.

ggplot's qplot does not execute on sourcing

And also tried to create a bash script starting with #!/usr/bin/env Rscript, nothing seems to work.

Is there a solution? I need to pass an argument to the R function

Herman Toothrot
  • 1,463
  • 3
  • 23
  • 53
  • Do other (base graphics) plots work? – cbeleites unhappy with SX Dec 05 '19 at 13:10
  • @cbeleitessupportsMonica I have added x11() and it works with base and ggplot, but as soon as the plot is finished the window closes. I also tried to add prompt <- "hit spacebar to close plots" – Herman Toothrot Dec 05 '19 at 15:04
  • 1
    *prompt <- "hit spacebar to close plots"* => do you mean you added a `readline ()` statement? The X11() device (or any other graphics device) will be closed when Rscript finishes. This doesn't hurt for pdf () or similar devices, as the file with the plot will persist, but an X11 () graph will be gone. – cbeleites unhappy with SX Dec 05 '19 at 15:08

0 Answers0