# using 'R' in sage: can not plot. errors of X11 and PNG

Hi! We are going to use SAGE this semester in a course which has a piece of statistics. For this part we planned to compile Sage worksheets with the option 'R'. But we have the following errors. If we write the instruction:

x<-c(12,2,4)

y<-x

plot(x,y)

the instruction works in a mac which has a local sage (packages are on the hard disk). However, the pupils will use the sage server of our university (v4.6), wich gives the error message:

Error in png() : X11 is not available

The same error is obtained with a local installation on windows 7 (v4.7.2, with VM virtual box).

Besides, if we try at sage server on sagenb.org (v4.7.2), we obtain a different error:

Error in X11(paste("png::", filename, sep = ""), width, height, pointsize, : unable to start device PNG In addition: Warning message: In png() : no png support in this version of R

Please, does anybody know how to fix it?

Thank you.

edit retag close merge delete

Sort by » oldest newest most voted

If you look at the list of "related questions" on the right of this question, you'll see several things which should answer this for you. The most useful one should be Compiling R with PNG support (see in particular Jason Grout's answer).

Basically, you need to have certain other libraries installed and somehow made known to Sage for this to work on a Linux server. The 4.8 VirtualBox solution should now have this enabled (right, Volker?). Unfortunately, sagenb.org is currently missing this support as well. Maybe this should get fixed... see this sage-devel thread.

Edit: This now works on sagenb.org! Thanks to William for installing them.

more

Plotting with r does indeed work in the virtual machine now:

more

That's what I thought, though you could have just commented that they should download the 4.8 ova file ;-) Interesting that one can post screenshots, I hadn't thought of that before, but it would be very natural in this context.

( 2012-01-26 11:56:40 +0200 )edit

Yes I mainly posted the screenshot because I wanted to try out this feature ;-)

( 2012-01-26 14:54:10 +0200 )edit

Thank you for your quick and accurate answers. I'm sorry I did not know the questions on the right part of the screen. I tried to do a search and only found some threads and finally got lost. I'm not an expert.

I will try installing the 4.8 ova file but I have to wait, because the current version in the servers I have checked is 4.7.2.

But mainly I'm interested in fixing the sage server of my university. So I will show your answers to the administrator of that server to see what is more suitable.

I will tell you the end of the story. Thank you so much!!!

more

Great, update us!

( 2012-01-26 16:34:14 +0200 )edit

As the questions on the side, I just wanted to point out that this, somewhat surprisingly, often turns out to be quite helpful. Of course, they wouldn't show up until you've asked the question, so you could hardly have known.

( 2012-01-26 16:34:49 +0200 )edit

Hi!

I've been trying to apply your advices and this is the result:

First I tried the just downloaded 4.8 ova file and the sagenb.org server. In both cases the result is the same, that is:

The instructions:

x=r([1,2,3,4,5])
y=r([1,2,3,2,1])
r.plot(x,y)


work fine.

However, when I write:

x<-c(1,2,3,4,5)
y<-c(1,2,3,2,1)
plot(x,y)


and try to compile with 'R', I don't obtain any error message, but the graphic is not shown. That is, I obtain an empty output.

Finally I tried with my ubuntu 10.4. and sage 4.8. I installed packages libpango1.0-dev and libcairo-dev with xorg-dev previously installed. I got an error that says 'Unable to start r' So I guess this is a matter of my lack of competence in linux and not a general problem.

more

1

In R, the plot command will write an Rplots.pdf to the current directory and not print anything on screen. Yes, using R thorugh sage is a bit more user-friendly. Arguably this is what Sage is about, making it easier to use scientific software.

( 2012-02-01 15:40:48 +0200 )edit
1

You'd probably need to open and close a graphics device. See http://user2010.org/slides/Crisman.pdf, especially the part about "This example is due to Andrzej Giniewicz."

( 2012-02-01 21:18:06 +0200 )edit
1

Thank you! It works now.

( 2012-02-03 09:26:11 +0200 )edit

Sweet!

( 2012-02-03 10:43:10 +0200 )edit

(I have to point out that it is unfortunate that I had to use four space characters just in order to do that last comment.)

( 2012-02-03 10:43:51 +0200 )edit

Two setup to do so: command:sage -f r it will rebuilt the R in sage to enable plotting support. and then: png() x<-c(12,2,4) y<-x plot(x,y) dev.off()

more