Our goal is to estimate the percentage of all locations within the continential United States that are within 1 mile of a road AND to determine the uncertainty in this estimate.
To do this we will make use of R's mosaic package, Google Maps and code provided by Sara Stoudt*, Yue Cao, Dana Udwin and Nicholas Horton.
First install the mosaic package (you can pick any CRAN mirror) and load it.
require(mosaic)
nsamp = 20
samples = rgeo(n=nsamp, latlim = c(25, 50), lonlim=c(-65, -125))
myroadless = data.frame(sample=1:nsamp, latitude=round(samples$lat, 4),longitude=round(samples$lon, 4),
withinContinent=c(rep(NA, nsamp)),within1mile=c(rep(NA, nsamp)),
location=character(nsamp))
rm(samples, nsamp)
myroadless
print(myroadless)
getLocation <- function(counter, radi=1) {
googleMap(myroadless[counter,"latitude"], myroadless[counter,"longitude"],
mark=TRUE, maptype="terrain", radius=radi, browse=TRUE)
}
getLocation(1) #default 1 mile radius
# or to change the size of the circle
getLocation(1, radi=5) # a five mile radius
getLocation(2) # to look at the 2nd location
Try zooming out to see where you are. Complete your data sheet noting whether each location is within the continental US, whether it is within 1 mile of a road and including a quick note about the location.