I am trying to use the solution here for applying a bounding box of coordinates when plotting a ggmap, as specifying get_map() using a bounding box does not work (is converted to center and zoom).
However, I end up with a lot of extra gray around my plot. I would like to have a plot fitted nicely where the bounding coordinates are (xmin, xmax, ymin, ymax) = (-170,-30, -60, 110)
# Get a Google satellite map of North and South America
map <- get_map(location = c(-100, 20), zoom = 2, maptype = "satellite", source = "google")
ggmap(map)
I would like to have a plot fitted to the coordinates described above.
# Attempt to scale the x and y axes
ggmap(map) +
scale_x_continuous(limits = c(-170, -30), expand=c(0,0)) +
scale_y_continuous(limits = c(-60, 110), expand=c(0,0))
What I end up with is a plot that looks like this:
Cropped nicely but with excessive gray space at the top.
Edit: I used R 3.3.3 in RStudio 1.0.136, with ggmap 2.7 and ggplot2 2.2.0
What you are trying to do exceeds the boundaries of the map. The maximum positive/negative Latitude
on a mercator-style projection is 85.0511... / -85.0511...
, because arctan(sinh(Pi)) * 180 / Pi = 85.0511288
.
This code will yield a correct result:
ggmap(map, extent = "panel") +
scale_x_continuous(limits = c(-170, -30), expand=c(0,0)) +
scale_y_continuous(limits = c(-60, 85), expand=c(0,0))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.