5  Map Projections

5.1 Set Up The Map

It is not necessary to understand the code here. But I learned a lot from: https://plotly.com/r/#maps.

5.2 Call plotly Library

Show the code
library(plotly)

5.3 A Basic Map

Show the code
# a very basic map could be created with: 

library(plotly)

mymap0 <- plot_geo() # create basic map; read into mymap0

mymap0 # replay

5.4 A More Advanced Map

This part is admittedly a little complicated, mostly because I added options to get the map to look exactly the way that I wanted.

Show the code
mymap <- plot_geo() %>%
  layout(title = "Demonstration Map", 
         geo = list(showland = TRUE, # show land
                    landcolor = toRGB("darkgrey"), # land color
                    showcountries = TRUE, # show countries
                    showocean = FALSE, # show ocean
                    oceancolor = "lightblue", # ocean color
                    lataxis = list(showgrid = TRUE, # latitude options
                                   gridcolor = toRGB("grey")),
                    lonaxis = list(showgrid = TRUE, # longitude options
                                   gridcolor = toRGB("grey")))) 

mymap # replay

5.5 Map Projections

5.5.1 Globe (Orthographic)

Show the code
mymap %>% 
  layout(geo = list(projection = list(type = 'orthographic')))

5.5.2 Mercator

Perpendicular latitude and longitude. Can be helpful in some kinds of navigation, but areas are distorted, especially as one approaches the poles.

Show the code
mymap %>% 
  layout(geo=list(projection = list(type = 'mercator')))

5.5.3 Mollweide

An equal area projection.

Show the code
mymap %>% 
  layout(geo=list(projection = list(type = 'mollweide')))

5.5.4 Robinson

An attempt to compromise between equal areas and a natural looking map.

Show the code
mymap %>% 
  layout(geo=list(projection = list(type = 'robinson')))