[R] Manage several graphical devices in interactive mode
Duncan Murdoch
murdoch.duncan at gmail.com
Sun Jul 25 18:07:38 CEST 2010
On 25/07/2010 10:03 AM, (Ted Harding) wrote:
> On 25-Jul-10 13:22:11, Sébastien Bihorel wrote:
>> Dear R-users,
>>
>> Does anybody know a good way to create and use several graphical
>> devices at the same time in interactive mode? Ideally, I'd like
>> to open 2 to 3 devices and assign names to them. This way, I could
>> make any addition/modification/update to a particular device using
>> its name.
>>
>> I did not see anything like a name argument in ?X11. Is there an
>> alternative?
>>
>> Thanks in advance for your feeback.
>> Sebastien
>
> You can certainly do this "by hand". The basic R terminal is device
> number 1. If you do X11() (or invoke it implicitly by using a 'plot'
> command) this will be device number 2. With just this one open, any
> 'plot' (or plot-related) commands will re-use it.
>
> However, having opened device #2, you can do X11() again and get a
> second graphics device which will be number 3. And so on, for as many
> additional devices as you like.
>
> By default, the device that the results of any 'plot' command are
> sent to will be the most recently opened one. However, you can select
> the device using the command dev.set(n) where n ( = 2,3,... ) is the
> device you want to use. The device which is "active" will be shown
> by the word "(ACTIVE)" attached to its display. All other devices
> will show "(inactive)".
>
> You could "name" your devices by indexing a vector (2:n) by names.
>
> Try the following, Starting with no graphics devices open:
>
> X11() # dev 2
> X11() # dev 3
> X11() # dev 4 ## This one is currently active
That's the right idea, but I wouldn't count on the numbers coming out 2,
3, 4: what if another device was already opened? Better to use
dev.cur() just after you open a new device to find out what its number
was. So do something like
X11()
plotA <- dev.cur()
X11()
plotB <- dev.cur()
X11()
plotC <- dev.cur()
dev.set(plotA) # first one is active
etc.
Duncan Murdoch
> ## Arange these so that you can see all their top bars
> devN <- c(plotA=2,plotB=3,plotC=4)
>
> dev.set(devN["plotA"]) # dev 2 is active
>
> dev.set(devN["plotC"]) # dev 4 is active
>
> dev.set(devN["plotB"]) # dev 3 is active
>
> dev.set(devN["plotA"]) # dev 2 is active
>
> dev.set(devN["plotC"]) # dev 4 is active
>
> Hoping this helps,
> Ted.
>
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 25-Jul-10 Time: 15:03:14
> ------------------------------ XFMail ------------------------------
>
> ______________________________________________
> R-help at r-project.org 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.
More information about the R-help
mailing list