mrub
mrub

Reputation: 513

How can I increase the map size in a plot?

I want to plot points in an openstreetmap. To determine a suitable range for the map I want to use min() and max() and increase the size by 10%:

library(OpenStreetMap)
coords <- data.frame(cbind(c(-2.121821, -2.118570, -2.124278),
c(51.89437, 51.90330, 51.90469)))
topleft <- c(max(coords[,2]) + 0.1 * max(coords[,2]),
min(coords[,1]) - 0.1 * min(coords[,1]))
bottomright <- c(min(coords[,2]) - 0.1 * min(coords[,2]),
max(coords[,1]) + 0.1 * max(coords[,1]))

map <- openproj(openmap(topleft, bottomright, zoom = "16", type="osm"))

When I now try to create the map R eats up all my resources and I have to kill the process. Is there a better way to achieve this?

R version 3.0.1 (2013-05-16)
Platform: x86_64-unknown-linux-gnu (64-bit)
other attached packages:
[1] ggplot2_0.9.3.1     OpenStreetMap_0.3.1 rgdal_0.8-14        raster_2.2-12       sp_1.0-14          
[6] rJava_0.9-6        

Upvotes: 2

Views: 2384

Answers (1)

Josh O&#39;Brien
Josh O&#39;Brien

Reputation: 162401

You're extending the range incorrectly, as you'll see if you have a look at the computed values of topleft and bottomright.

A less error-prone approach might use the function extendrange() (which is used by many R plotting functions to add a little buffer around the most extreme points in the plot).

xx <- extendrange(coords[[1]], f=0.10)
yy <- extendrange(coords[[2]], f=0.10)
tl <- c(max(yy), min(xx))
br <- c(min(yy), max(xx))
map <- openproj(openmap(tl, br, zoom="16", type="osm"))
plot(map)

enter image description here

Upvotes: 1

Related Questions