问题
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
来源:https://stackoverflow.com/questions/59181206/running-rscript-containing-ggplot-from-linux-command-line-through-xterm