Draw Maps

Hi Casey, I pulled up the article I mentioned to you today about drawing maps in R. Since it is in Chinese, I summarized the article and write in English :)

The article introduce two ways of drawing the map. One is by package “maps”. I assumed you already downloaded and installed it. The R code is as follows:

library(maps)

# U.S. Map:
map("state", fill = TRUE, col = rainbow(209), mar = c(0, 0, 2, 0))
title("U.S. Maps")

plot of chunk unnamed-chunk-1

You can also draw specific states, for example:

map("state", region = c("Michigan", "Indiana", "Ohio", "Illinois", "Wisconsin"), 
    fill = TRUE, col = rainbow(5), mar = c(2, 3, 4, 3))
title("U.S. Midwest")

plot of chunk unnamed-chunk-2

I believe there more things in this package. You could read the documents.

By Package ggmap and mapproj

Install it.

library(ggmap)
## Loading required package: ggplot2
library(mapproj)

# Retrieve geographic information
geocode("Western Michigan University", output = "more")
##      lon   lat       type     loctype
## 1 -85.62 42.28 university approximate
##                                                                            address
## 1 western michigan university, 1903 west michigan avenue, kalamazoo, mi 49008, usa
##   north south  east   west postal_code       country
## 1 42.29 42.27 -85.6 -85.62       49008 united states
##   administrative_area_level_2 administrative_area_level_1  locality
## 1                   kalamazoo                    michigan kalamazoo
##                 street streetNo point_of_interest
## 1 west michigan avenue     1903              <NA>
##                         query
## 1 Western Michigan University

To draw Michigan and U.S. map:

map <- get_map(location = "Michigan", zoom = 7, maptype = "hybrid")
ggmap(map)

plot of chunk unnamed-chunk-4


map <- get_map(location = "united states", zoom = 4)
ggmap(map)

plot of chunk unnamed-chunk-4

I believe there are other ways to draw maps for sure.

Have fun!!!

Lincoln