rggplot2ggmap

Plot map within latitude/longitude boundaries


Plot of map

I am trying to plot a map of the wider Indian Ocean using ggmap. I have selected various latitudes/longitudes which I would like to form the corners of my map. However, when I try to plot the map with R, it produces a map of all the continents, rather than solely the area which I would like it to plot. The above map is what the code is outputting, and I have highlighted the area which I wish to plot in the red box.

This is the code which I have attempted:

bbox <- make_bbox(lon = data$Longitude, lat = data$Latitude, f=1)
map <- get_map(location = bbox, source = "google", maptype = "satellite")
plot <- ggmap(map)

Data:

structure(list(Latitude = c(18.682744, -27.706318, 17.65651, 
-21.006735), Longitude = c(46.252432, 43.179057, 100.89364, 104.064258
)), class = "data.frame", row.names = c(NA, -4L))

Solution

  • Your value f=1, is too large of a fraction and this is inflating the size of the map.

    data<-structure(list(Latitude = c(18.682744, -27.706318, 17.65651, 
                            -21.006735), Longitude = c(46.252432, 43.179057, 100.89364, 104.064258
                            )), class = "data.frame", row.names = c(NA, -4L))
    
    bbox <- make_bbox(lon = data$Longitude, lat = data$Latitude, f=1)
    bbox
     #left    bottom     right       top 
     #-17.70614 -74.09538 164.94946  65.07181  
    

    if you look at your bounding box, the top to bottom is going from 65 North to -74 South.

    If you set f=0.05 (the default) the size of the map, it is more manageable.

    bbox <- make_bbox(lon = data$Longitude, lat = data$Latitude, f=0.05)
    box
    
    #    left    bottom     right       top 
    #40.13480 -30.02577 107.10852  21.00220 
    

    Now the box's latitude changed from 21 North to -30 South, much closer to your desired size.