To download the development version of mapit:
library(knitr); library(ggmap); library(mapit) opts_chunk$set(cache=FALSE, tidy=FALSE, warning=FALSE, fig.path='inst/readme/figure/') ## knitr::knit2html("README.Rmd")
# install.packages("devtools") library(devtools) install_github("mapit", "trinker")
Note: Mac users might be required to install the appropriate version XTools from the Apple Developer site in order to install the development version. You may need to register as an Apple developer. An older version of XTools may also be required.
You are welcome to: submit suggestions and bug-reports at: https://github.com/trinker/mapit/issues send a pull request on: https://github.com/trinker/mapit/ * compose a friendly e-mail to: [email protected]
This is an R implementation of Jan Philip Matuschek's bounding box article: Finding Points Within a Distance of a Latitude/Longitude Using Bounding Coordinates.
So here we can look at the area within one square mile of the White House:
bounding_box(38.89768, -77.03653, 1)
Let's apply it. Here's an example plotting a bounding box around the 2012 Olympic Stadium:
library(ggplot2); library(ggmap) bb <- bounding_box(lon = -0.016179, lat = 51.538525, 1) mapImageData <- get_map(location = c(lon = -0.016179, lat = 51.538525), color = "color", source = "google", maptype = "hybrid", zoom = 14) ggmap(mapImageData, extent = "device", ylab = "Latitude", xlab = "Longitude") + geom_rect(aes(xmin = bb[1, 1], xmax = bb[1, 2], ymin = bb[2, 1], ymax = bb[2, 2]), color="red", fill=NA, size=2) + geom_point(data=data.frame(lon = -0.016179, lat = 51.538525), size=7, color="yellow")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.