How do I change which R Graphics Device is active?

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

How do I change which R Graphics Device is active?

Mark Knecht
Hello,
   If I execute

X11()
plot( stuff )
X11()
plot( other stuff)

then at this point I have two windows with plots and the second
graphics window is active. I don't see the devices using ls().

1) Without destroying the second window how do I make the first window
active again?
2) How do I destroy a specific window when I'm done with it?
3) Is there some generic way to understand what windows are out there
at any given time or do I need to create some sort of list and keep
track of it myself?

In general I'd like to have 4 or 5 windows and be able to switch and
update individual plots as the needs arise. Is there a way to name
these devices/windows? I don't see any examples of this sort of thing
in the help file. Maybe there's a different add-on package I don't yet
know about?

Thanks,
Mark

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
markknecht@gmail.com
Reply | Threaded
Open this post in threaded view
|

Re: How do I change which R Graphics Device is active?

milton ruser
How about:

dev.cur()
dev.list()
dev.next(which = dev.cur())
dev.prev(which = dev.cur())
dev.off(which = dev.cur())
dev.set(which = dev.next())
dev.new(...)
graphics.off()
dev.cur()
dev.list()
dev.next(which = dev.cur())
dev.prev(which = dev.cur())
dev.off(which = dev.cur())
dev.set(which = dev.next())
dev.new(...)
graphics.off()
:-) bests

milton

On Tue, Jun 30, 2009 at 12:07 PM, Mark Knecht <[hidden email]> wrote:

> Hello,
>   If I execute
>
> X11()
> plot( stuff )
> X11()
> plot( other stuff)
>
> then at this point I have two windows with plots and the second
> graphics window is active. I don't see the devices using ls().
>
> 1) Without destroying the second window how do I make the first window
> active again?
> 2) How do I destroy a specific window when I'm done with it?
> 3) Is there some generic way to understand what windows are out there
> at any given time or do I need to create some sort of list and keep
> track of it myself?
>
> In general I'd like to have 4 or 5 windows and be able to switch and
> update individual plots as the needs arise. Is there a way to name
> these devices/windows? I don't see any examples of this sort of thing
> in the help file. Maybe there's a different add-on package I don't yet
> know about?
>
> Thanks,
> Mark
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How do I change which R Graphics Device is active?

Mark Knecht
Thanks milton! Beautiful!

Cheers,
Mark

On Tue, Jun 30, 2009 at 9:15 AM, milton ruser<[hidden email]> wrote:

> How about:
>
> dev.cur()
> dev.list()
> dev.next(which = dev.cur())
> dev.prev(which = dev.cur())
> dev.off(which = dev.cur())
> dev.set(which = dev.next())
> dev.new(...)
> graphics.off()
> dev.cur()
> dev.list()
> dev.next(which = dev.cur())
> dev.prev(which = dev.cur())
> dev.off(which = dev.cur())
> dev.set(which = dev.next())
> dev.new(...)
> graphics.off()
> :-) bests
>
> milton
>
> On Tue, Jun 30, 2009 at 12:07 PM, Mark Knecht <[hidden email]> wrote:
>>
>> Hello,
>>   If I execute
>>
>> X11()
>> plot( stuff )
>> X11()
>> plot( other stuff)
>>
>> then at this point I have two windows with plots and the second
>> graphics window is active. I don't see the devices using ls().
>>
>> 1) Without destroying the second window how do I make the first window
>> active again?
>> 2) How do I destroy a specific window when I'm done with it?
>> 3) Is there some generic way to understand what windows are out there
>> at any given time or do I need to create some sort of list and keep
>> track of it myself?
>>
>> In general I'd like to have 4 or 5 windows and be able to switch and
>> update individual plots as the needs arise. Is there a way to name
>> these devices/windows? I don't see any examples of this sort of thing
>> in the help file. Maybe there's a different add-on package I don't yet
>> know about?
>>
>> Thanks,
>> Mark
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
markknecht@gmail.com
Reply | Threaded
Open this post in threaded view
|

Re: How do I change which R Graphics Device is active?

barry rowlingson
In reply to this post by milton ruser
On Tue, Jun 30, 2009 at 5:15 PM, milton ruser<[hidden email]> wrote:

> How about:
>
> dev.cur()
> dev.list()
> dev.next(which = dev.cur())
> dev.prev(which = dev.cur())
> dev.off(which = dev.cur())
> dev.set(which = dev.next())
> dev.new(...)
> graphics.off()
> dev.cur()
> dev.list()
> dev.next(which = dev.cur())
> dev.prev(which = dev.cur())
> dev.off(which = dev.cur())
> dev.set(which = dev.next())
> dev.new(...)
> graphics.off()
> :-) bests
>

 To keep track, call dev.cur() after creating a new plot and assign it
to something memorable. Here's how to keep a histogram and an xy plot:

> dev.new();histPlot = dev.cur()
> dev.new();xyPlot = dev.cur()
> dev.set(histPlot);hist(runif(100))
X11cairo
       2
> dev.set(xyPlot);plot(1:10)
X11cairo
       3

 You just have to remember to call dev.set before your particular plot.


Barry

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How do I change which R Graphics Device is active?

Ted.Harding-2
On 30-Jun-09 16:48:15, Barry Rowlingson wrote:

> To keep track, call dev.cur() after creating a new plot
> and assign it to something memorable. Here's how to keep
> a histogram and an xy plot:
>
>> dev.new();histPlot = dev.cur()
>> dev.new();xyPlot = dev.cur()
>> dev.set(histPlot);hist(runif(100))
> X11cairo
>        2
>> dev.set(xyPlot);plot(1:10)
> X11cairo
>        3
>
> You just have to remember to call dev.set before your particular plot.
>
> Barry

Barry, spot on! If there were a prize for postings with
simplicity, clarity, conciseness and usability, I would nominate
yours (especially in the "Why didn't *I* think of that?" category).

Cheers,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <[hidden email]>
Fax-to-email: +44 (0)870 094 0861
Date: 30-Jun-09                                       Time: 18:33:40
------------------------------ XFMail ------------------------------

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How do I change which R Graphics Device is active?

Mark Knecht
In reply to this post by barry rowlingson
On Tue, Jun 30, 2009 at 9:48 AM, Barry
Rowlingson<[hidden email]> wrote:

> On Tue, Jun 30, 2009 at 5:15 PM, milton ruser<[hidden email]> wrote:
>> How about:
>>
>> dev.cur()
>> dev.list()
>> dev.next(which = dev.cur())
>> dev.prev(which = dev.cur())
>> dev.off(which = dev.cur())
>> dev.set(which = dev.next())
>> dev.new(...)
>> graphics.off()
>> dev.cur()
>> dev.list()
>> dev.next(which = dev.cur())
>> dev.prev(which = dev.cur())
>> dev.off(which = dev.cur())
>> dev.set(which = dev.next())
>> dev.new(...)
>> graphics.off()
>> :-) bests
>>
>
>  To keep track, call dev.cur() after creating a new plot and assign it
> to something memorable. Here's how to keep a histogram and an xy plot:
>
>> dev.new();histPlot = dev.cur()
>> dev.new();xyPlot = dev.cur()
>> dev.set(histPlot);hist(runif(100))
> X11cairo
>       2
>> dev.set(xyPlot);plot(1:10)
> X11cairo
>       3
>
>  You just have to remember to call dev.set before your particular plot.
>
>
> Barry
>

Makes great sense and fits in very nicely with what I'm doing.

Thanks!

- Mark

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
markknecht@gmail.com
Reply | Threaded
Open this post in threaded view
|

Re: How do I change which R Graphics Device is active?

barry rowlingson
In reply to this post by Ted.Harding-2
On Tue, Jun 30, 2009 at 6:33 PM, Ted
Harding<[hidden email]> wrote:

> Barry, spot on! If there were a prize for postings with
> simplicity, clarity, conciseness and usability, I would nominate
> yours (especially in the "Why didn't *I* think of that?" category).

 Thanks Ted!

 It's just a shame dev.new() doesn't return the device number, since
that would make things even simpler:

# does not work like this:
 xyPlot = dev.new()
histPlot = dev.new()

 Instead it returns whatever the device function (X11,png,postscript
etc) returns, and they all seem to return NULLs. I suppose in the
future a device function might return something useful.

Barry

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How do I change which R Graphics Device is active?

Mark Knecht
On Tue, Jun 30, 2009 at 11:45 AM, Barry
Rowlingson<[hidden email]> wrote:

> On Tue, Jun 30, 2009 at 6:33 PM, Ted
> Harding<[hidden email]> wrote:
>
>> Barry, spot on! If there were a prize for postings with
>> simplicity, clarity, conciseness and usability, I would nominate
>> yours (especially in the "Why didn't *I* think of that?" category).
>
>  Thanks Ted!
>
>  It's just a shame dev.new() doesn't return the device number, since
> that would make things even simpler:
>
> # does not work like this:
>  xyPlot = dev.new()
> histPlot = dev.new()
>
>  Instead it returns whatever the device function (X11,png,postscript
> etc) returns, and they all seem to return NULLs. I suppose in the
> future a device function might return something useful.
>
> Barry
>

You could wrap it in a function of your own making, right?

AddNewDev = function() {dev.new();AddNewDev=dev.cur()}

histPlot=AddNewDev()

Seems to work.

- Mark

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
markknecht@gmail.com
Reply | Threaded
Open this post in threaded view
|

Re: How do I change which R Graphics Device is active?

barry rowlingson
On Tue, Jun 30, 2009 at 8:05 PM, Mark Knecht<[hidden email]> wrote:

> You could wrap it in a function of your own making, right?
>
> AddNewDev = function() {dev.new();AddNewDev=dev.cur()}
>
> histPlot=AddNewDev()
>
> Seems to work.

 You leaRn fast :) Probably better style is:

 newDev = function(){dev.new();return(dev.cur())}

 - which returns the value explicitly with return().

Barry

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How do I change which R Graphics Device is active?

Mark Knecht
On Tue, Jun 30, 2009 at 12:12 PM, Barry
Rowlingson<[hidden email]> wrote:

> On Tue, Jun 30, 2009 at 8:05 PM, Mark Knecht<[hidden email]> wrote:
>
>> You could wrap it in a function of your own making, right?
>>
>> AddNewDev = function() {dev.new();AddNewDev=dev.cur()}
>>
>> histPlot=AddNewDev()
>>
>> Seems to work.
>
>  You leaRn fast :) Probably better style is:
>
>  newDev = function(){dev.new();return(dev.cur())}
>
>  - which returns the value explicitly with return().
>
> Barry
>

Thanks Ted. I've missed this return function. I'll start using that.

Cheers,
Mark

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
markknecht@gmail.com
Reply | Threaded
Open this post in threaded view
|

Re: How do I change which R Graphics Device is active?

Mark Knecht
Oops sorry. Thanks BARRY!

On Tue, Jun 30, 2009 at 12:14 PM, Mark Knecht<[hidden email]> wrote:

> On Tue, Jun 30, 2009 at 12:12 PM, Barry
> Rowlingson<[hidden email]> wrote:
>> On Tue, Jun 30, 2009 at 8:05 PM, Mark Knecht<[hidden email]> wrote:
>>
>>> You could wrap it in a function of your own making, right?
>>>
>>> AddNewDev = function() {dev.new();AddNewDev=dev.cur()}
>>>
>>> histPlot=AddNewDev()
>>>
>>> Seems to work.
>>
>>  You leaRn fast :) Probably better style is:
>>
>>  newDev = function(){dev.new();return(dev.cur())}
>>
>>  - which returns the value explicitly with return().
>>
>> Barry
>>
>
> Thanks Ted. I've missed this return function. I'll start using that.
>
> Cheers,
> Mark
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
markknecht@gmail.com
Reply | Threaded
Open this post in threaded view
|

Re: How do I change which R Graphics Device is active?

hadley wickham
In reply to this post by barry rowlingson
On Tue, Jun 30, 2009 at 2:12 PM, Barry
Rowlingson<[hidden email]> wrote:

> On Tue, Jun 30, 2009 at 8:05 PM, Mark Knecht<[hidden email]> wrote:
>
>> You could wrap it in a function of your own making, right?
>>
>> AddNewDev = function() {dev.new();AddNewDev=dev.cur()}
>>
>> histPlot=AddNewDev()
>>
>> Seems to work.
>
>  You leaRn fast :) Probably better style is:
>
>  newDev = function(){dev.new();return(dev.cur())}
>
>  - which returns the value explicitly with return().

R isn't C! ;)  I'd claim idiomatic R only uses return for special
cases (i.e. when you can terminate the function early)

Hadley

--
http://had.co.nz/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How do I change which R Graphics Device is active?

Don MacQueen
My version would be

   newDev <-  function() { dev.new(); invisible( dev.cur() ) }

I agree with Hadley that return() is redundant in this instance.
Using invisible() suppresses automatic printing of the returned value
when it is not being assigned to a variable, thus making it more like
dev.new().

While we're at it, consider

   newDev <-  function(...) { dev.new(...); invisible( dev.cur() ) }

which should allow one to pass through optional arguments (which only
makes sense if they're valid for dev.new(), of course).

-Don

At 7:18 PM -0500 6/30/09, hadley wickham wrote:

>On Tue, Jun 30, 2009 at 2:12 PM, Barry
>Rowlingson<[hidden email]> wrote:
>>  On Tue, Jun 30, 2009 at 8:05 PM, Mark Knecht<[hidden email]> wrote:
>>
>>>  You could wrap it in a function of your own making, right?
>>>
>>>  AddNewDev = function() {dev.new();AddNewDev=dev.cur()}
>>>
>>>  histPlot=AddNewDev()
>>>
>>>  Seems to work.
>>
>>   You leaRn fast :) Probably better style is:
>>
>  >  newDev = function(){dev.new();return(dev.cur())}
>>
>>   - which returns the value explicitly with return().
>
>R isn't C! ;)  I'd claim idiomatic R only uses return for special
>cases (i.e. when you can terminate the function early)
>
>Hadley
>
>--
>http:// had.co.nz/
>
>______________________________________________
>[hidden email] mailing list
>https:// stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http:// www. R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.


--
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How do I change which R Graphics Device is active?

barry rowlingson
In reply to this post by hadley wickham
On Wed, Jul 1, 2009 at 3:30 PM, Don MacQueen<[hidden email]> wrote:
> My version would be
>
>  newDev <-  function() { dev.new(); invisible( dev.cur() ) }
>
> I agree with Hadley that return() is redundant in this instance. Using
> invisible() suppresses automatic printing of the returned value when it is
> not being assigned to a variable, thus making it more like dev.new().

 Hmmm. I really like using explicit return calls in my functions. It
seems, to me, to make it clear that I intend to return a value and
that value is going to be useful. How can others tell (without looking
at the ample documentation, of course) that you intend your function
to have a meaningful return value and it's not just "falling through"?

As The Zen of Python puts it:

 Explicit is better than implicit.
 Readability counts.

but you know, hey, whatever you want to do :)

Barry

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How do I change which R Graphics Device is active?

Mark Knecht
On Wed, Jul 1, 2009 at 7:45 AM, Barry
Rowlingson<[hidden email]> wrote:

> On Wed, Jul 1, 2009 at 3:30 PM, Don MacQueen<[hidden email]> wrote:
>> My version would be
>>
>>  newDev <-  function() { dev.new(); invisible( dev.cur() ) }
>>
>> I agree with Hadley that return() is redundant in this instance. Using
>> invisible() suppresses automatic printing of the returned value when it is
>> not being assigned to a variable, thus making it more like dev.new().
>
>  Hmmm. I really like using explicit return calls in my functions. It
> seems, to me, to make it clear that I intend to return a value and
> that value is going to be useful. How can others tell (without looking
> at the ample documentation, of course) that you intend your function
> to have a meaningful return value and it's not just "falling through"?
>
> As The Zen of Python puts it:
>
>  Explicit is better than implicit.
>  Readability counts.
>
> but you know, hey, whatever you want to do :)
>
> Barry
>

As a newbie and being that I have no formal or job related programming
experience I personally like having a return value as it makes me
think about what I'm doing. That's just me though.

- Mark

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
markknecht@gmail.com