Posts

Showing posts from July, 2018

Producing a map with 5 lines of code

Image
Over the past year, I have been exploring the geospatial capabilities of various R packages.  Today, I want to share the most basic of geospatial capabilities, which is producing a map.  Using R, you can do this in just 5 lines of code. Let's produce a map of Boston, Massachusetts.  Boston has a longitude of -71.0588801 and a latitude of 42.3600825.  Since we list x and y coordinates in order (i.e. we list y after x), we list longitude (the horizontal coordinate) before latitude (the vertical coordinate).  Let's create our map! Code line 1: install.packages("ggmap") This command installs the ggmap package in your R environment. Code line 2: library(ggmap) This command loads the ggmap package in your R environment. Code line 3: boston <- c(lon = -71.0588801, lat = 42.3600825) This line creates a variable called "boston" and assigns the lon and lat coordinates in it. Code line 4: boston_map <- get_map(boston, zoom = 13, scale = 1...