[R] locator() in a multi-figure setting using mfrow()
Christoph Lehmann
christoph.lehmann at gmx.ch
Mon Sep 6 11:40:24 CEST 2004
I know, that I can use par(mfg = c(i,u)) to get the correct x,y
coordinates of one of the 8 matrices/subimages, but how can I get the i
and the j, means how can I know in which of the 8 images I am clicking in?
thanks
Christoph
Christoph Lehmann wrote:
> Hi
>
> based on some code from Thomas Petzoldt (see below), I have a question,
> about how to use locator() in a mfrow() multi-figure setting. I am sure
> this should be a kind of problem, which other people face too?
>
> we have 8 matrices each 10x10 fields, plotted as mfrow = c(2,4).
>
> how can I get, using locator(), the correct index of a field of one of
> the 8 matrices? means, I should get 3 values: the matrix I am in (a
> value between 1..8), and the corresponding x and y coordinates (each in
> 1..10)
>
> many, thanks for your kind help.
>
> ---
> opar <- par(mfrow = c(2,4))
> slices <- 8
> m <- matrix(runif(100),10,10)
> my.list <- list()
> for (slice in 1:slices) {
> my.list[[slice]] <- m
> }
>
> for (slice in 1:slices) {
> x <- 1*(1:25)
> y <- 1*(1:25)
> z <- my.list[[slice]]
> image(list(x = 0:9, y = 0:9, z = z))
> }
> par(opar) #restore device parameters
>
>
> p <- locator(1)
> c(round(p$x), round(p$y))
> ---
>
> how can I get the "correct" location in the sense of a
> 3d info: (a) which slice (p$slice) (b) p$x (c) p$y
>
> so that it could be used in the sense of:
>
> my.list[[p$slice]][round(p$x), round(p$y)]
>
>
> christoph
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
More information about the R-help
mailing list