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 Slide

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

    View 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 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 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 Slide

  6. GET YOUR MAP!
    p zoom = 11, maptype ='terrain',color = 'color'))

    View Slide

  7. USE THE GGPLOT2 BELLS & WHISTLES

    View Slide

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

    View Slide

  9. DENSITY OF DATA POINTS
    Set the geom_point alpha parameter

    View Slide

  10. LAYERING OF DATA SETS
    Two geom_point function calls!

    View Slide

  11. CUSTOM LABELS
    Use the geom_label_repel function

    View Slide

  12. DENSITY AREA
    Use the stat_density2d function

    View Slide

  13. DENSITY LINES
    Use the geom_density2d function

    View Slide

  14. SUB GROUPS
    Subset and use facet_wrap

    View Slide

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

    View Slide

  16. OTHER GOOGLE MAP TYPES
    Different google map types

    View Slide

  17. STAMEN MAP TYPES
    Different stamen map types

    View Slide

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

    View 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 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 Slide