Tuesday, 15 March 2011

openstreetmap - Box around OSM plot in R -



openstreetmap - Box around OSM plot in R -

can set box around openstreetmap plot in r? box doesn't fit map itself, , rect doesn't plot @ all..

require(openstreetmap) m = openmap(c(52,-1), c(51,1), zoom=8, type='osm') par(mai=rep(.2,4)) plot(m, removemargin=f) box() rect(-1, 51, 1, 52, border='black', lwd=2)

box() plots box around whole plot area, apparently includes white space.

the problem rect coordinates not you'd expect: check adding axes plot. right boundary coordinates can obtained m object itself: m$bbox, see str(m). utilize these draw rectangle this:

require(openstreetmap) m = openmap(c(52,-1), c(51,1), zoom=8, type='osm') # par(mai=rep(.2,4)) plot(m, removemargin=f) # add together axes check coordinates, uncomment see # axis(1); axis(2) p1 = m$bbox$p1 # bottom left p2 = m$bbox$p2 # top right rect(xleft=p1[1], ybottom=p1[2], xright=p2[1], ytop=p2[2], xpd=na, lwd=2, border='red')

r openstreetmap

No comments:

Post a Comment