Slide 1

Slide 1 text

GGMAP + GGPLOT2 = BEAUTIFUL MAPS By: Laura Ellis - IBM Cloud & littlemissdata.com

Slide 2

Slide 2 text

— All R Data Viz Junkies THERE IS NO EXCUSE FOR A SAD GRAPH WITH R

Slide 3

Slide 3 text

DISCUSSION POINTS • Get your map! • Customize your map • Take advantage of the ggplot2 bells and whistles • Play with map types • Create Icon Maps with ggimage

Slide 4

Slide 4 text

FROM DATA.GOV - US GOVERNMENTS OPEN DATA SEATTLE 911 DATA This dataset is all the Police responses to 9-1-1 calls within the city. Police response data shows all officers dispatched. To protect the security of a scene, the safety of officers and the public, and sensitive ongoing investigation, these events are added to the data.seattle.gov only after the incident is considered safe to close out. Data is refreshed on a 4 hour interval.

Slide 5

Slide 5 text

GGMAP • The get_map function provides a general approach for quickly obtaining maps from multiple sources. Can also use get_googlemap function for google maps. Notes: Material above from NCEAS cheat sheet OSM and Cloudmade not covered in this talk. • There are 4 main map types: • Google - Roadmap, terrain, satellite, hybrid • Stamen - Terrain, Toner, Watercolor • OSM - Open Street Map * • Cloudmade *

Slide 6

Slide 6 text

GET YOUR MAP! p <- ggmap(get_googlemap(center = c(lon = -122.335167, lat = 47.608013), zoom = 11, maptype ='terrain',color = 'color'))

Slide 7

Slide 7 text

USE THE GGPLOT2 BELLS & WHISTLES

Slide 8

Slide 8 text

ADD YOUR DATA POINTS Use geom_point with color set to a group

Slide 9

Slide 9 text

DENSITY OF DATA POINTS Set the geom_point alpha parameter

Slide 10

Slide 10 text

LAYERING OF DATA SETS Two geom_point function calls!

Slide 11

Slide 11 text

CUSTOM LABELS Use the geom_label_repel function

Slide 12

Slide 12 text

DENSITY AREA Use the stat_density2d function

Slide 13

Slide 13 text

DENSITY LINES Use the geom_density2d function

Slide 14

Slide 14 text

SUB GROUPS Subset and use facet_wrap

Slide 15

Slide 15 text

HIGHLIGHT A GROUP Filter and layer with multiple geom_point functions

Slide 16

Slide 16 text

OTHER GOOGLE MAP TYPES Different google map types

Slide 17

Slide 17 text

STAMEN MAP TYPES Different stamen map types

Slide 18

Slide 18 text

ADD ICONS Using the geom_image function from the ggimage package

Slide 19

Slide 19 text

TUTORIALS AVAILABLE • Full tutorial and code available on my website and GitHub • https://www.littlemissdata.com/blog/maps • https://www.littlemissdata.com/blog/iconmap • https://github.com/lgellis/MiscTutorial/

Slide 20

Slide 20 text

AMAZING RESOURCES • ggmap: Spatial Visualization with ggplot2 - by David Kahle and Hadley Wickham • https://journal.r-project.org/archive/2013-1/kahle-wickham.pdf • ggmap cheat sheet by National Center for Ecological Analysis and Synthesis (NCEAS) • https://www.nceas.ucsb.edu/~frazier/RSpatialGuides/ggmap/ggmapChea tsheet.pdf