Saving a plot in R-LINUX

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Saving a plot in R-LINUX

Augusto.Sanabria

Good day,

Is there any way to save a plot produced by
R in a LINUX (Debian) machine?

The window opened by R to put the plot in,
does not give any option to save it (there
are options to move, close, minimise it, etc.
but not to save it). How do you do that?

Thanks,

Augusto



--------------------------------------------
Augusto Sanabria. MSc, PhD.
Mathematical Modeller
Risk Research Group
Geospatial & Earth Monitoring Division
Geoscience Australia (www.ga.gov.au)
Cnr. Jerrabomberra Av. & Hindmarsh Dr.
Symonston ACT 2609
Ph. (02) 6249-9155

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Saving a plot in R-LINUX

Dirk Eddelbuettel

On 13 January 2006 at 11:02, [hidden email] wrote:
| Is there any way to save a plot produced by
| R in a LINUX (Debian) machine?

It is the same on every platform and ...

| The window opened by R to put the plot in,
| does not give any option to save it (there
| are options to move, close, minimise it, etc.
| but not to save it). How do you do that?

... explained in section 12.6 of the fine 'R Introduction' manual available
in Debian in each one of the packages

        r-doc-info
        r-doc-html
        r-doc-pdf

for your choice of format to read.

Short form:

> pdf("/tmp/foo.pdf")
> plot(x, y)
> dev.off()

Don't forget the dev.off(). And do read the manual, section 12.6, also on the
web at eg http://cran.r-project.org/doc/manuals/R-intro.html#Graphics

Dirk

--
Hell, there are no rules here - we're trying to accomplish something.
                                                  -- Thomas A. Edison

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Saving a plot in R-LINUX

Prof Brian Ripley
That does not save the current plot though, and dev.copy() and
dev.print() can do so.  They _are_ in the manual Dirk pointed you at.

Windows versions of R have other options, e.g. savePlot() and menu items
to save the plot, and my guess is that is what
'[hidden email]' has seen.

I don't see what this has to do with this list rather than R-help, though.

On Thu, 12 Jan 2006, Dirk Eddelbuettel wrote:

>
> On 13 January 2006 at 11:02, [hidden email] wrote:
> | Is there any way to save a plot produced by
> | R in a LINUX (Debian) machine?
>
> It is the same on every platform and ...
>
> | The window opened by R to put the plot in,
> | does not give any option to save it (there
> | are options to move, close, minimise it, etc.

Those `options' are from your X11 Window Manager, not from R.

> | but not to save it). How do you do that?
>
> ... explained in section 12.6 of the fine 'R Introduction' manual available
> in Debian in each one of the packages
>
> r-doc-info
> r-doc-html
> r-doc-pdf
>
> for your choice of format to read.
>
> Short form:
>
>> pdf("/tmp/foo.pdf")
>> plot(x, y)
>> dev.off()
>
> Don't forget the dev.off(). And do read the manual, section 12.6, also on the
> web at eg http://cran.r-project.org/doc/manuals/R-intro.html#Graphics
>
> Dirk
>
> --
> Hell, there are no rules here - we're trying to accomplish something.
>                                                  -- Thomas A. Edison
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Saving a plot in R-LINUX

Vaidotas Zemlys
In reply to this post by Dirk Eddelbuettel
On 1/13/06, Dirk Eddelbuettel <[hidden email]> wrote:

>
> On 13 January 2006 at 11:02, [hidden email] wrote:
> | Is there any way to save a plot produced by
> | R in a LINUX (Debian) machine?
>
> It is the same on every platform and ...
>
> | The window opened by R to put the plot in,
> | does not give any option to save it (there
> | are options to move, close, minimise it, etc.
> | but not to save it). How do you do that?
>

What about using dev.copy? Or am I missing something? In windows there
is a context menu when you click with the right mouse button, which
lets you choose how do you want to save the plot. On linux I came up
with such function, which albeit not perfectly but does the job:

d2b <- function(file="Rplot%d.bmp",height=4,width=4,res=150,which=dev.cur(),...)
{
    if(which!=dev.cur()) {
        cur <- dev.cur()
        dev.set(which)
    }
    else cur <- NULL

    dev.copy(device=bitmap,file=file,height=height,width=width,point=8,res=res,...)
    dev.off()
    if(!is.null(cur))dev.set(cur)
    else dev.set(which)
}

It copies told device (current by default) to bitmap file. This
function could be easily adapted for copying to other formats.

Since the answer was too easy, probably I did not understand question
correctly. In that case please ignore this message.

Vaidotas Zemlys
--
Doctorate student, http://www.mif.vu.lt/katedros/eka/katedra/zemlys.php
Vilnius University

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Saving a plot in R-LINUX

Augusto.Sanabria
In reply to this post by Augusto.Sanabria
Vaidotas,

The command 'dev2bitmap(plotname, type="jpeg")'
does the trick too.

Thanks to all those who sent helpful tips. It seems that I
am posting these questions to the wrong list, my apologies!

Regards,

Augusto


--------------------------------------------
Augusto Sanabria. MSc, PhD.
Mathematical Modeller
Risk Research Group
Geospatial & Earth Monitoring Division
Geoscience Australia (www.ga.gov.au)
Cnr. Jerrabomberra Av. & Hindmarsh Dr.
Symonston ACT 2609
Ph. (02) 6249-9155
 
 


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On
Behalf Of Vaidotas Zemlys
Sent: Saturday, 14 January 2006 12:10 AM
To: [hidden email]
Subject: Re: [Rd] Saving a plot in R-LINUX


On 1/13/06, Dirk Eddelbuettel <[hidden email]> wrote:

>
> On 13 January 2006 at 11:02, [hidden email] wrote:
> | Is there any way to save a plot produced by
> | R in a LINUX (Debian) machine?
>
> It is the same on every platform and ...
>
> | The window opened by R to put the plot in,
> | does not give any option to save it (there
> | are options to move, close, minimise it, etc.
> | but not to save it). How do you do that?
>

What about using dev.copy? Or am I missing something? In windows there is a
context menu when you click with the right mouse button, which lets you
choose how do you want to save the plot. On linux I came up with such
function, which albeit not perfectly but does the job:

d2b <-
function(file="Rplot%d.bmp",height=4,width=4,res=150,which=dev.cur(),...)
{
    if(which!=dev.cur()) {
        cur <- dev.cur()
        dev.set(which)
    }
    else cur <- NULL

 
dev.copy(device=bitmap,file=file,height=height,width=width,point=8,res=res,..
.)
    dev.off()
    if(!is.null(cur))dev.set(cur)
    else dev.set(which)
}

It copies told device (current by default) to bitmap file. This function
could be easily adapted for copying to other formats.

Since the answer was too easy, probably I did not understand question
correctly. In that case please ignore this message.

Vaidotas Zemlys
--
Doctorate student, http://www.mif.vu.lt/katedros/eka/katedra/zemlys.php
Vilnius University

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel