Skip to content

interacting with plots

9 messages · Frazier, Tyler James, Karl Ove Hufthammer, Greg Snow

#
You could try something like:

library(rgdal)
library(sp)
scot_BNG <- readOGR(dsn=dsn, layer="scot_BNG")
plot(scot_BNG)
tmp <- SpatialPoints(locator(1))
proj4string(tmp) <- proj4string(scot_BNG)
over(tmp, scot_BNG)
# or
tmp2 <- over(scot_BNG, tmp)
plot( scot_BNG[!is.na(tmp2),], add=TRUE, col='green')

Does that do what you want?

On Thu, Aug 16, 2012 at 9:05 AM, Frazier, Tyler James
<tyler.j.frazier at tu-berlin.de> wrote:

  
    
#
My example used locator(1) to get one click, but if you just use
locator() (without the 1) then you can click in as many places as you
want, then it should show you the info for all of them).  If you want
to click and see the results, then click again and see the new
results, etc. then you could put my code into a while loop.  Panning
and zooming using the mouse would be a bit more difficult, but you
might get a similar effect by setting the limits when plotting (and
you can get limits to set using the locator function again).

On Thu, Aug 16, 2012 at 11:09 AM, Frazier, Tyler James
<tyler.j.frazier at tu-berlin.de> wrote:

  
    
#
Frazier, Tyler James skreiv:
I would recommend using QGIS instead of R for these kinds of tasks:

  http://www.qgis.org/

It?s very easy to use, and supports both panning, zooming and clicking
to show polygon attributes (and has a whole lot of other useful features).
You can even integrate QGIS and R.
#
Determining if a point is in a polygon is not as simple a task as
might be assumed (I can see that it is in there, why can't the
computer?).  So the computer has to do this check for all (or maybe
just some) 12,438 features, so it is not surprising if it is a little
slow.  The people who created and maintain the sp package would be
better able to address issues of how to speed it up (I am not one of
those who get that credit).  For this task it may be better to use a
tool outside of R, qgis has been mentioned and there may be others.

On Thu, Aug 16, 2012 at 12:47 PM, Frazier, Tyler James
<tyler.j.frazier at tu-berlin.de> wrote:

  
    
1 day later
#
Frazier, Tyler James wrote:

            
I haven?t used it myself, but yes, I believe mangeR is the best solution.