Reputation: 40573
I have this little script
library(ggplot2)
print(qplot(1:10, 1:10))
readLines("stdin", n = 1)
that I am trying to run with
r -f littleScript.R
Unfortunately, the expected plot is not displayed. In fact, nothing is displayed at all. I understand that I should use print()
on qplot()
's output, yet, it doesn't help in my case.
Upvotes: 1
Views: 63
Reputation: 24945
When running from a script, R doesn't invoke graphics by default.
You can add the command x11() to enable it:
library(ggplot2)
x11()
print(qplot(1:10, 1:10))
readLines("stdin", n = 1)
Alternatively you could save the plot by adding a call to jpeg/pdf etc etc:
library(ggplot2)
jpeg("myfilepath.jpg")
print(qplot(1:10, 1:10))
dev.off()
readLines("stdin", n = 1)
Upvotes: 1