0

Is there a way to zoom in a map on an R spatial polygons object.

i.e. if I have polygons for a whole country but I want to zoom in on a specific city and just plot that area how do I do that ?

At the moment I am just plotting a chloropleth of the whole country like this:

    colours<-(brewer.pal(9, "YlGn"))
    brks<-classIntervals(poly$var1, n=9, style="quantile")
    brks<-brks$brks
    plot(ED, col=colours[findInterval(poly$var1, brks,all.inside=TRUE)], axes=F, border=FALSE)

I wanna zoom in and plot a rectangular area around a particular city but can't figure out how.

3

Use xlim and ylim args to plot:

require(spdep) # for sample data 
data(columbus)
plot(columbus)
axis(1);axis(2) # see where we are
plot(columbus,xlim=c(8,9),ylim=c(12,13))

OR if you don't know the coords get them using locator:

plot(columbus)
xy=locator(2,"p") # click two corners
plot(columbus,xlim=xy$x,ylim=xy$y)

OR use zoom from the raster package:

require(raster)
plot(columbus)
zoom(columbus) # click corners
  • Thanks!I also had the idea to subset the map using a larger scale area code - but that would not be nice and rectangular so I look your solution better! – user2498193 Aug 25 '13 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.