Ggmap map resizing

I would like to create a map that is not perfectly square, but rectangular, and this is the size that I define.

require(ggmap) tenmile <- get_map(location = c(lon = -122.486328, lat = 48.862813), color = "color", source = "google", maptype = "roadmap", zoom = 12) tenmile.map <- ggmap(tenmile, extent = "device", ylab = "Latitude", xlab = "Longitude")+ggtitle("GEOMean for Data from Oct 2013-Nov 2014") tenmile.map + geom_point(data=pp, aes(x=lon, y=lat, size=geomean), color="red", alpha=0.5) + geom_text(data=pp, aes(x=lon, y=lat, label = site), size=3, vjust = 1.25, hjust = -0.1) 

I would publish photos of what I get and what I want, but I do not have enough reputation points to send images. = - (

+6
source share
2 answers

If you want to keep the original bounds of the bounding box, but just change your shape, you can adjust the aspect ratio. If you want to change the borders of the bounding box, then get the map as before, but set its limits using coord_fixed() (or coord_cartesian() ). Or you can adjust both aspect ratio and bounding box limits.

 tenmile <- get_map(location = c(lon = -122.486328, lat = 48.862813), color = "color", source = "google", maptype = "roadmap", zoom = 12) tenmile.map <- ggmap(tenmile, ylab = "Latitude", xlab = "Longitude")+ggtitle("GEOMean for Data from Oct 2013-Nov 2014") + coord_fixed(xlim = c(-122.55, -122.40), ratio = 2/1) 
+2
source

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.

0
source

Source: https://habr.com/ru/post/980906/


All Articles