Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a map within the latitude and longitude range?

Tags:

r

ggplot2

ggmap

How do I get a map with in a specific minimum and maximum limits of latitude and longitude using ggmap in R?

I'm new to using ggmap, as of now I was able to implement this:

center <- c(mean(src$longitude),mean(src$latitude))
zoom <- min(MaxZoom(range(src$latitude),range(src$longitude)))
hdf <- get_map(location=center,zoom=zoom)

Help file says location can be mentioned as an address, longitude/latitude pair (in that order), or left/bottom/right/top bounding box. I couldn't find any helpful material on implementing the bounding box for ggmap online.

like image 618
san8055 Avatar asked Jan 13 '23 20:01

san8055


1 Answers

I'm not sure you can do it in the download stage, but how about in the plotting stage like this:

map <- get_map()
p1 <- ggmap( map )
p2 <- ggmap( map )+
scale_x_continuous( limits = c( -95.5 , -95.3 ) , expand = c( 0 , 0 ) )+
scale_y_continuous( limits = c( 29.6 , 29.8 ) , expand = c( 0 , 0 ) )
require( gridExtra )
grid.arrange( p1 , p2 , nrow = 1 )

enter image description here

like image 178
Simon O'Hanlon Avatar answered Jan 16 '23 02:01

Simon O'Hanlon