Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Making beautiful maps in R with ggmap and ggplot2

ATX GIS Day
November 13, 2019

Making beautiful maps in R with ggmap and ggplot2

Laura Ellis @littlemissdata, Analytics Architect, IBM Cloud

ATX GIS Day

November 13, 2019
Tweet

More Decks by ATX GIS Day

Other Decks in Technology

Transcript

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

    View full-size slide

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

    View full-size slide

  3. 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

    View full-size slide

  4. 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.

    View full-size slide

  5. 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 *

    View full-size slide

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

    View full-size slide

  7. USE THE GGPLOT2 BELLS & WHISTLES

    View full-size slide

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

    View full-size slide

  9. DENSITY OF DATA POINTS
    Set the geom_point alpha parameter

    View full-size slide

  10. LAYERING OF DATA SETS
    Two geom_point function calls!

    View full-size slide

  11. CUSTOM LABELS
    Use the geom_label_repel function

    View full-size slide

  12. DENSITY AREA
    Use the stat_density2d function

    View full-size slide

  13. DENSITY LINES
    Use the geom_density2d function

    View full-size slide

  14. SUB GROUPS
    Subset and use facet_wrap

    View full-size slide

  15. HIGHLIGHT A GROUP
    Filter and layer with multiple geom_point functions

    View full-size slide

  16. OTHER GOOGLE MAP TYPES
    Different google map types

    View full-size slide

  17. STAMEN MAP TYPES
    Different stamen map types

    View full-size slide

  18. ADD ICONS
    Using the geom_image function from the ggimage package

    View full-size slide

  19. 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/

    View full-size slide

  20. 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

    View full-size slide