Tomas
Tomas

Reputation: 59495

creating PNG plots on the linux terminal

I have an R script that I run on a linux server (Debian Wheezy 7.7). This script is meant to do some computations and generate plots into PNGs. Unfortunatelly I get an error:

> savePlot("myplot", "png")
Error in savePlot("myplot", "png") :
  can only copy from 'X11(type="*cairo")' devices

How do I get around this? I am only connected from Win XP with PuTTy, I don't have any X-windows set up on my XP and I don't want to bother with this - all I need is to run the script and produce the PNGs. Thanks!

Upvotes: 2

Views: 1081

Answers (2)

sakovias
sakovias

Reputation: 1434

On my Ubuntu distribution, calling x11() before plot() resolved this issue. This blog post gives more details on different operating systems.

Upvotes: 1

Marc in the box
Marc in the box

Reputation: 11995

You may have more luck calling the device internally:

png("plot.png")
    plot(1)
dev.off()

If you don't want to bother with opening an instance of R, you could save the above script (e.g. "script.01.R") and run the following from the console:

R CMD BATCH script.01.R

This should also work to create the .png.

Upvotes: 3

Related Questions