choropleths
play

Choropleths Data Visualization with ggplot2 Chapter Contents - PowerPoint PPT Presentation

DATA VISUALIZATION WITH GGPLOT2 Choropleths Data Visualization with ggplot2 Chapter Contents Maps GIS = Geographic Information System Choropleths Cartographic maps Animations Data Visualization with ggplot2


  1. DATA VISUALIZATION WITH GGPLOT2 Choropleths

  2. Data Visualization with ggplot2 Chapter Contents ● Maps ● GIS = Geographic Information System ● Choropleths ● Cartographic maps ● Animations

  3. Data Visualization with ggplot2 Choropleths > library(ggplot2) > usa <- map_data("usa") > ggplot(usa, aes(long, lat, group = group)) + geom_polygon() + Bunch of polygons coord_map() 50 45 40 lat 35 30 25 − 120 − 100 − 80 long

  4. Data Visualization with ggplot2 Choropleths > library(ggplot2) > library(ggalt) > usa <- map_data("usa") > ggplot(usa, aes(long, lat, group = group)) + geom_polygon() + coord_proj("+proj=wintri") 50 45 40 lat 35 30 25 − 120 − 100 − 80 long

  5. Data Visualization with ggplot2 Many polygons > states <- map_data("state") > ggplot(states, aes(long, lat, fill = region, group = group)) + geom_polygon(color = "white") + coord_map()

  6. Data Visualization with ggplot2 Weed prices value 350 300 250

  7. Data Visualization with ggplot2 Weed prices value 400 350 300 250 200

  8. Data Visualization with ggplot2 Alternatives oregon ● washington ● colorado ● california ● montana ● nevada ● idaho ● new mexico ● utah ● michigan ● alaska ● arizona ● florida ● hawaii ● maine ● rhode island ● georgia ● indiana ● ohio ● texas ● wyoming ● mississippi ● kentucky ● alabama ● region nebraska ● connecticut ● south carolina ● new york ● arkansas ● district of columbia ● massachusetts ● new jersey ● north carolina ● kansas ● tennessee ● wisconsin ● illinois ● minnesota ● west virginia ● missouri ● new hampshire ● oklahoma ● pennsylvania ● delaware ● louisiana ● iowa ● virginia ● maryland ● vermont ● south dakota ● north dakota ● 200 250 300 350 400 value

  9. Data Visualization with ggplot2 Alternatives michigan ● indiana ● ohio ● nebraska ● Midwest kansas ● wisconsin ● illinois ● minnesota ● missouri ● iowa ● south dakota ● north dakota ● maine ● rhode island ● connecticut ● Northeast new york ● massachusetts ● new jersey ● new hampshire ● pennsylvania ● vermont state ● florida ● georgia ● texas ● mississippi ● kentucky ● alabama ● south carolina South ● arkansas ● north carolina ● tennessee ● west virginia ● oklahoma ● delaware ● louisiana ● virginia ● maryland ● oregon ● washington ● colorado ● california ● montana ● nevada West ● idaho ● new mexico ● utah ● alaska ● arizona ● hawaii ● wyoming ● 200 250 300 350 400 value

  10. Data Visualization with ggplot2 Alternatives michigan ● indiana ● ohio Midwest East North Central ● wisconsin ● illinois ● nebraska ● kansas ● minnesota ● missouri Midwest West North Central ● iowa ● south dakota ● north dakota ● new york ● new jersey Northeast Mid − Atlantic ● pennsylvania ● maine ● rhode island ● connecticut ● Northeast New England massachusetts ● new hampshire ● vermont ● mississippi ● state kentucky ● South East South Central alabama ● tennessee ● florida ● georgia ● south carolina ● north carolina ● South South Atlantic west virginia ● delaware ● virginia ● maryland ● texas ● arkansas ● South West South Central oklahoma ● louisiana ● colorado ● montana ● nevada ● idaho ● West Mountain new mexico ● utah ● arizona ● wyoming ● oregon ● washington ● california West Pacific ● alaska ● hawaii ● 200 250 300 350 400 value

  11. DATA VISUALIZATION WITH GGPLOT2 Let’s practice!

  12. DATA VISUALIZATION WITH GGPLOT2 Cartographic Maps

  13. Data Visualization with ggplot2 Cartographic map ● Drawn ● Topographical maps ● Altitude, infrastructure ... ● Photographic ● Satellite images ● Hybrid ● ggmap

  14. Data Visualization with ggplot2 > # Default style - zoom = 3 > library(ggmap) > def_03 <- get_map(location = "Berlin, Germany", zoom = 3) > ggmap(def_03, extent = "device")

  15. Data Visualization with ggplot2 > # Default style - zoom = 13 > library(ggmap) > def_13 <- get_map(location = "Berlin, Germany", zoom = 13) > ggmap(def_13, extent = "device")

  16. Data Visualization with ggplot2 > # Default style - zoom = 20 > library(ggmap) > def_20 <- get_map(location = "Berlin, Germany", zoom = 20) > ggmap(def_20, extent = "device")

  17. Data Visualization with ggplot2 > # stamen/watercolor - zoom = 13 > library(ggmap) > wc_13 <- get_map(location = "Berlin, Germany", zoom = 13, source = "stamen", maptype = "watercolor") > ggmap(wc_13, extent = "device")

  18. Data Visualization with ggplot2 > # stamen/toner - zoom = 13 > library(ggmap) > ton_13 <- get_map(location = "Berlin, Germany", zoom = 13, source = "stamen", maptype = "toner") > ggmap(ton_13, extent = "device")

  19. Data Visualization with ggplot2 > # stamen/hybrid - zoom = 13 > library(ggmap) > hyb_13 <- get_map(location = "Berlin, Germany", zoom = 13, source = "stamen", maptype = "hybrid") > ggmap(ton_13, extent = "device")

  20. Data Visualization with ggplot2 > # google/satellite - zoom = 13 > library(ggmap) > sat_13 <- get_map(location = "Berlin, Germany", zoom = 13, source = "google", maptype = "satellite") > ggmap(ton_13, extent = "device")

  21. Data Visualization with ggplot2 Get coordinates > berlin_sites <- c("Brandenburger Tor", "Potsdamer Platz", 
 "Victory Column Berlin", "Checkpoint Charlie", "Reichstag Berlin", "Alexander Platz") > xx <- geocode(berlin_sites) Information from URL : http://maps.googleapis.com/maps/... Information from URL : ... > # Add column with cleaned up names > xx$location <- sub(" Berlin", "", berlin_sites) > str(xx) 'data.frame': 6 obs. of 3 variables: $ lon : num 13.4 13.4 13.4 13.4 13.4 ... $ lat : num 52.5 52.5 52.5 52.5 52.5 ... $ location: chr "Brandenburger Tor" "Potsdamer Platz" ...

  22. Data Visualization with ggplot2 > # google/roadmap - zoom = 13 > road_13 <- get_map(location = "Berlin, Germany", zoom = 13, 
 source = "google", maptype = "roadmap") > ggmap(road_13, extent = "device")

  23. Data Visualization with ggplot2 > # google/roadmap - zoom = 13 > road_13 <- get_map(location = "Berlin, Germany", zoom = 13, 
 source = "google", maptype = "roadmap") > ggmap(road_13, extent = "device") + geom_point(data = xx, col = "red") ● ● ● ● ●

  24. Data Visualization with ggplot2 > bbox <- make_bbox(lon = xx$lon, lat = xx$lat, f = .1) > boxed_14 <- get_map(location = bbox, zoom = 14, source = "google", maptype = "roadmap") > ggmap(boxed_14, extent = "device") + geom_point(data = xx, col = "red") ● ● ● ●

  25. Data Visualization with ggplot2 > bbox <- make_bbox(lon = xx$lon, lat = xx$lat, f = .1) > boxed_14 <- get_map(location = bbox, zoom = 14, source = "google", maptype = "roadmap") > ggmap(boxed_14, extent = "device") + aes(col = location), size = 3) + geom_point(data = xx, scale_colour_brewer(palette = "Set1") location ● Alexander Platz ● ● Brandenburger Tor ● ● Checkpoint Charlie ● Potsdamer Platz ● Reichstag ● ● Victory Column ●

  26. Data Visualization with ggplot2 Final Plot Alexander Platz Reichstag Brandenburger Tor Victory Column Potsdamer Platz Checkpoint Charlie

  27. DATA VISUALIZATION WITH GGPLOT2 Let’s practice!

  28. DATA VISUALIZATION WITH GGPLOT2 Animations

  29. Data Visualization with ggplot2 Animations ● Dense temporal data ● Great exploratory tool ● Several ways ● for loop to produce gif ● animation ● gganimate

  30. Data Visualization with ggplot2 Motion Chart ● Hans Rosling ● Karolinska Institute in Stockholm ● Founder of Gapminder ● UN data ● Life expectancy, GDP ...

  31. Data Visualization with ggplot2 Gapminder data > # import tab-delimited data > gapminder <- read.delim("gapminder.tsv", stringsAsFactors = FALSE) > str(gapminder) 'data.frame': 1704 obs. of 6 variables: $ country : chr "Afghanistan" "Afghanistan" "Afghanistan" ... $ year : int 1952 1957 1962 1967 1972 1977 1982 1987 ... $ pop : num 8425333 9240934 10267083 11537966 13079460 ... $ continent: chr "Asia" "Asia" "Asia" "Asia" ... $ lifeExp : num 28.8 30.3 32 34 36.1 ... $ gdpPercap: num 779 821 853 836 740 ...

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend