Skip to contents

In ggmap, all maps (class ggmap) have the bb attribute, a data frame bounding box specification in terms of the bottom left and top right points of the spatial extent. This function converts this specification to a named double vector (with names left, bottom, right, top) specification that is used in some querying functions (e.g. get_stadiamap).

Usage

bb2bbox(bb)

Arguments

bb

a bounding box in bb format (see examples)

Value

a bounding box in bbox format (see examples)

Author

David Kahle david@kahle.io

Examples


if (FALSE) # cut down on R CMD check time

# grab a center/zoom map and compute its bounding box
gc <- geocode("white house, washington dc")
map <- get_map(gc)
#> Error in get_map(gc): `location` improperly specified, see `ggmap::get_map()`.
(bb <- attr(map, "bb"))
#> Error in eval(expr, envir, enclos): object 'map' not found
(bbox <- bb2bbox(bb))
#> Error in eval(expr, envir, enclos): object 'bb' not found

# use the bounding box to get a Stadia map
stadMap <- get_stadiamap(bbox)
#> Error in eval(expr, envir, enclos): object 'bbox' not found

ggmap(map) +
  geom_point(
    aes(x = lon, y = lat),
    data = gc, colour = "red", size = 3
  )
#> Error in eval(expr, envir, enclos): object 'map' not found

ggmap(stadMap) +
  geom_point(
    aes(x = lon, y = lat),
    data = gc, colour = "red", size = 3
  )
#> Error in eval(expr, envir, enclos): object 'stadMap' not found