class: center, middle, inverse, title-slide .title[ # Datos Espaciales ] .author[ ### Felipe Antonio Dzul Manzanilla ] .date[ ### 2022: Last compiled 2022-10-25 ] --- class: left, top
# **Temas** <hr style="height:2px;border-width:0;color:#330019;background-color:#330019"> - Datos espaciales. - Tipos de Mapas. - Información básica para un mapa. - Mapas estáticos en R. - Mapas en base. - Mapas en ggplot2. - Mapas en tmap. - Mapas en mapsf.. - Mapas interactivos en R - leaflet - plolty - tmap - mapview --- # Clasificación de los Datos Espaciales <hr style="height:2px;border-width:0;color:#330019;background-color:#330019">
.footnote[[Krainski et al 2019](https://www.taylorfrancis.com/books/mono/10.1201/9780429031892/advanced-spatial-modeling-stochastic-partial-differential-equations-using-inla-elias-krainski-virgilio-g%C3%B3mez-rubio-haakon-bakka-amanda-lenzi-daniela-castro-camilo-daniel-simpson-finn-lindgren-h%C3%A5vard-rue)] --- # Tipos de mapas <hr style="height:2px;border-width:0;color:#330019;background-color:#330019">
--- # Datos Espaciales .panelset[ .panel[.panel-name[Point Pattern Data]
] .panel[.panel-name[Geoestatistical Data]
] .panel[.panel-name[Areal Data]  ] ] --- # Datos Espaciales .panelset.sideways[ .panel[.panel-name[Square Grid] ```r # Step 1. load the locality #### loc <- rgeomex::extract_ageb(locality = c("Guadalajara", "Zapopan", "Tlaquepaque", "Tonalá"), cve_geo = "14") # Step 2. make the grid ##### grid_square = sf::st_make_grid(x = loc$locality, square = TRUE, cellsize = 0.01) grid_square <-grid_square[loc$locality] # Step 3. plot the grid #### ggplot2::ggplot() + ggplot2::geom_sf(data = loc$locality, fill = NA, col = "#4285F4") + ggplot2::geom_sf(data = grid_square, fill = NA, col = "#DB4437") + cowplot::theme_map() ``` ] .panel[.panel-name[Square Grid map] <img src="index_files/figure-html/unnamed-chunk-2-1.png" width="100%" /> ] .panel[.panel-name[Hexagonal Grid] ```r # Step 2. make the grid ##### grid_hexagonal = sf::st_make_grid(x = loc$locality, square = FALSE, cellsize = 0.01) grid_hexagonal <-grid_hexagonal[loc$locality] # Step 3. plot the grid #### ggplot2::ggplot() + ggplot2::geom_sf(data = loc$locality, fill = NA, col = "#4285F4") + ggplot2::geom_sf(data = grid_hexagonal, fill = NA, col = "#DB4437") + cowplot::theme_map() ``` ] .panel[.panel-name[Hexagonal Grid Map] <img src="index_files/figure-html/unnamed-chunk-3-1.png" width="100%" /> ] .panel[.panel-name[Triangular Grid] ```r # Step 1. define the directory of ovitraps #### path_ovitraps <- "C:/Users/HOME/Dropbox/cenaprece_datasets/2022/14_jalisco" path_coord <- paste(path_ovitraps, "DescargaOvitrampasMesFco.txt", sep = "/") # Step 2. create the mesh #### spde_mod <- deneggs::eggs_hotspots(path_lect = path_ovitraps, cve_ent = 14, locality = c("Guadalajara", "Tlaquepaque", "Zapopan", "Tonalá"), path_coord = path_coord, longitude = "Pocision_X", latitude = "Pocision_Y", aproximation = "gaussian", integration = "eb", fam = "zeroinflatednbinomial1", k = 30, palette_vir = "magma", leg_title = "Huevos", plot = FALSE, hist_dataset = FALSE, ##### sem = lubridate::epiweek(Sys.Date())-1, var = "eggs", cell_size = 1000, alpha = .99) # Step 3. plot the grid #### ggplot2::ggplot() + inlabru::gg(data = spde_mod$mesh) + cowplot::theme_map() ``` ] .panel[.panel-name[Triangular Grid Map] <!-- --> ] ] --- # Requisito de un mapa <hr style="height:2px;border-width:0;color:#330019;background-color:#330019"> .can-edit.key-likes[ - La información geográfica (json, sh, etc). - La base de datos. - La variable de interes. ] --- # Mapas estáticos en R .panelset.sideways[ .panel[.panel-name[Base R] ```r # step 1. load municipality & add the dengue cases #### library(sf) x <- rgeomex::AGEM_inegi19_mx |> dplyr::filter(CVE_ENT %in% c("30")) |> dplyr::mutate(casos = rpois(n = dplyr::n(), lambda = 4)) # Step 2. plot the map with R base #### plot(x["casos"], key.pos = 4, axes = TRUE, graticule = TRUE, key.width = .2, key.length = .8) ``` ] .panel[.panel-name[Base R Map] <!-- --> ] .panel[.panel-name[ggplot2] ```r # step 1. load municipality & add the dengue cases #### library(sf) x <- rgeomex::AGEM_inegi19_mx |> dplyr::filter(CVE_ENT %in% c("30")) |> dplyr::mutate(casos = rpois(n = dplyr::n(), lambda = 4)) # Step 2. plot the map with ggplot2 #### ggplot2::ggplot() + ggplot2::geom_sf(data = x, ggplot2::aes(fill = casos)) + fishualize::scale_fill_fish() + ggspatial::annotation_scale(location = "bl") + ggspatial::annotation_north_arrow(location = "tr") ``` ] .panel[.panel-name[ggplot Map] <!-- --> ] .panel[.panel-name[tmap] ```r # step 1. load municipality & add the dengue cases #### library(sf) x <- rgeomex::AGEM_inegi19_mx |> dplyr::filter(CVE_ENT %in% c("30")) |> dplyr::mutate(casos = rpois(n = dplyr::n(), lambda = 4)) # Step 2. plot the map with tmap #### library(tmap) tmap::tm_shape(x) + tmap::tm_polygons(col = "casos") + tmap::tm_compass(position = c(.2, .9)) + tmap::tm_scale_bar(position = c(.1, .02)) ``` ] .panel[.panel-name[tmap Map] <!-- --> ] ] --- # Thanks! - ***Bio*** : https://fdzul.github.io/web_site_fadm/ - ***email*** : felipe.dzul.m@gmail.com - ***celular*** : 228 229 3419 - ***slides***: https://animated-longma-729cee.netlify.app/talks/spatial_data/#1 .footnote[La presentación fue creada via [**xaringan**](https://github.com/yihui/xaringan), [**revealjs**](https://revealjs.com/), [remark.js](https://remarkjs.com), [**knitr**](http://yihui.name/knitr), & [R Markdown](https://rmarkdown.rstudio.com) en [R]() & [RStudio](2.R_Scripts/libs/rstudio_leaflet/rstudio_leaflet.css).]