Sandy Muspratt's answer creates a rectangular map, but it is stretched. To get an unstretched map, the ratio must be adjusted to the ratio between the intervals of the parallels and meridians in the place of the map. I.e:
ratio = 1 / cos (latitude)
If latitude is given in degrees, it becomes:
ratio = 1 / cos (pi * latitude / 180)
Iβll give an example here using a map of Barcelona (Barcelona makes a good example for checking the stretch, because most of our streets form a square grid and the deformation becomes easily noticeable).
library(ggmap) library(mapproj) mapbcn <- get_map(location = 'Barcelona, Catalonia', zoom = 13) # square map (default) ggmap(mapbcn) # map cropped by latitude ggmap(mapbcn) + coord_fixed(ylim=c(41.36,41.41), ratio=1/cos(pi*41.39/180)) # map cropped by longitude ggmap(mapbcn) + coord_fixed(xlim=c(2.14, 2.18), ratio=1/cos(pi*41.39/180))
It should be noted that in this way the coordinates continue to work for the entire map (for example, to add points to the map) if the area of ββthe map is small enough not to take into account the curvature of the Earth, that is, assume that the meridians are parallel in the area indicated by the map. This may be inaccurate on a map covering several hundred kilometers and very incorrect on a continental scale map.
source share