class: center, middle, inverse, title-slide # Introdução ao uso de dados geoespaciais no R
## 9 Visualização de dados geoespaciais ### Maurício H. Vancine
Milton C. Ribeiro ### UNESP - Rio Claro
Laboratório de Ecologia Espacial e Conservação (LEEC) ### 25/10/2021-05/11/2021 --- class: clear background-image: url(img/geo_map_elements.png) background-size: 800px <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [Gimond (2021)](https://mgimond.github.io/Spatial/index.html) --- background-image: url(img/package_ggplot2.png), url(img/package_tmap.png), url(img/package_mapsf.png), url(img/package_leaflet.jpeg), url(img/box_anim.gif) background-size: 200px, 200px, 200px, 200px, 200px background-position: 60% 30%, 85% 30%, 50% 90%, 73% 90%, 95% 90% # 9 Visualização de dados geoespaciais ## Conteúdo 1. Elementos de um mapa 1. Pacotes para produção de mapas 1. Mapas estáticos 1. Mapas animados 1. Mapas interativos <br><br><br><br><br><br><br><br> [ggplot2](https://ggplot2.tidyverse.org/), [tmap](https://r-tmap.github.io/tmap/), [mapsf](https://riatelab.github.io/mapsf/), [leaflet](https://rstudio.github.io/leaflet/), [mapview](https://r-spatial.github.io/mapview/) --- # 9 Visualização de dados geoespaciais ## Script <br><br><br><br><br> ## .center[`09_script_intro_geoespacial_r.R`] --- background-image: url(img/geo_map_elements.png) background-size: 650px background-position: 95% 50% # 1. Elementos de um mapa ## Elementos <br> - Mapa principal - Mapa secundário - Título - Legenda - Barra de escala - Indicador de orientação (Norte) - Gride de coordenadas - Descrição do Sistema de Referência de Coordenadas - Informações de origem - Elementos auxiliares <br><br> [Gimond (2021)](https://mgimond.github.io/Spatial/index.html) --- # 2. Pacotes para produção de mapas ## Principais pacotes <br> - [ggplot2](https://ggplot2.tidyverse.org/): cria mapas elegantes usando a Gramática de Gráficos - [ggspatial](https://paleolimbot.github.io/ggspatial/): estrutura de dados espaciais para ggplot2 - [ggmap](https://cran.r-project.org/web/packages/ggmap/index.html): visualização espacial com ggplot2 - [tmap](https://mtennekes.github.io/tmap/): cria mapas temáticos - [mapsf](https://riatelab.github.io/mapsf/): cria mapas temáticos com dados vetoriais - [linemap](https://github.com/riatelab/linemap): cria mapas de linhas - [cartography](http://riatelab.github.io/cartography/docs/): cartografia temática - [cartogram](https://github.com/sjewo/cartogram): métodos de visualização para cartogramas - [googleway](http://symbolixau.github.io/googleway/): acessa Google Maps APIs para recuperar dados e traçar mapas - [rasterVis](https://oscarperpinan.github.io/rastervis/): métodos de visualização para dados raster - [mapview](https://r-spatial.github.io/mapview/): visualização interativa de dados espaciais em R - [leaflet](http://rstudio.github.io/leaflet/): cria Web Maps interativos com Leaflet - [plotly](https://plotly.com/r/maps/): crie gráficos interativos da Web por meio de ‘plotly.js’ - [mapedit](https://r-spatial.github.io/mapview/): edição interativa de dados geoespaciais em R --- background-image: url(img/geo_map_tmap.png) background-size: 700px background-position: 80% 80% # 3. Mapas estáticos ## Mapas estáticos são mapas simples e fixos para visualização de dados ## **Principais** 1. `plot()` (vários pacotes) 1. ggplot2 1. ggmap 1. tmap 1. mapsf 1. linemap 1. cartography 1. cartogram 1. googleway 1. rasterVis --- # 3. Mapas estáticos ## Função `plot()` ```r # biomas biomas <- geobr::read_biomes(showProgress = FALSE) %>% dplyr::filter(name_biome != "Sistema Costeiro") biomas ``` ``` ## Simple feature collection with 6 features and 3 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: -73.98304 ymin: -33.75115 xmax: -28.84785 ymax: 5.269581 ## Geodetic CRS: SIRGAS 2000 ## name_biome code_biome year geom ## 1 Amazônia 1 2019 MULTIPOLYGON (((-44.08515 -... ## 2 Caatinga 2 2019 MULTIPOLYGON (((-41.7408 -2... ## 3 Cerrado 3 2019 MULTIPOLYGON (((-43.39009 -... ## 4 Mata Atlântica 4 2019 MULTIPOLYGON (((-48.70814 -... ## 5 Pampa 5 2019 MULTIPOLYGON (((-52.82472 -... ## 6 Pantanal 6 2019 MULTIPOLYGON (((-57.75946 -... ``` --- # 3. Mapas estáticos ## Função `plot()` .pull-left[ ```r # plot plot(biomas) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-2-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## Função `plot()` .pull-left[ ```r # plot plot(biomas$geom, col = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3"), main = "Biomas do Brasil", axes = TRUE, graticule = TRUE) # legend legend(x = -73, y = -20, pch = 15, cex = 1, pt.cex = 2.5, legend = biomas$name_biome, col = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3")) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-3-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## Função `plot()` ```r # rio claro rc_2020 <- geobr::read_municipality(code_muni = 3543907, year = 2020, showProgress = FALSE) %>% sf::st_transform(crs = 4326) rc_2020 ``` ``` ## Simple feature collection with 1 feature and 7 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: -47.76521 ymin: -22.55203 xmax: -47.46188 ymax: -22.24368 ## Geodetic CRS: WGS 84 ## code_muni name_muni code_state abbrev_state name_state code_region ## 493 3543907 Rio Claro 35 SP São Paulo 3 ## name_region geom ## 493 Sudeste MULTIPOLYGON (((-47.46875 -... ``` --- # 3. Mapas estáticos ## Função `plot()` ```r # importar raster dem_rc <- raster::raster(here::here("03_dados", "raster", "srtm_27_17.tif")) %>% raster::crop(rc_2020) dem_rc ``` ``` ## class : RasterLayer ## dimensions : 370, 364, 134680 (nrow, ncol, ncell) ## resolution : 0.0008333333, 0.0008333333 (x, y) ## extent : -47.765, -47.46167, -22.55167, -22.24333 (xmin, xmax, ymin, ymax) ## crs : +proj=longlat +datum=WGS84 +no_defs ## source : memory ## names : srtm_27_17 ## values : 491, 985 (min, max) ``` --- # 3. Mapas estáticos ## Função `plot()` .pull-left[ ```r # plot plot(dem_rc) plot(rc_2020$geom, col = NA, border = "red", lwd = 2, add = TRUE) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-6-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## Função `plot()` .pull-left[ ```r # plot plot(dem_rc, col = viridis::viridis(10)) plot(rc_2020$geom, col = NA, border = "red", lwd = 2, add = TRUE) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-7-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## Função `plot()` ```r # listar arquivos files <- dir(path = here::here("03_dados", "raster"), pattern = "wc", full.names = TRUE) %>% grep(".tif", ., value = TRUE) # importar bioclim <- raster::stack(files) # names names(bioclim) <- c("bio01", paste0("bio", 10:19), paste0("bio0", 2:9)) bioclim ``` ``` ## class : RasterStack ## dimensions : 1080, 2160, 2332800, 19 (nrow, ncol, ncell, nlayers) ## resolution : 0.1666667, 0.1666667 (x, y) ## extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax) ## crs : +proj=longlat +datum=WGS84 +no_defs ## names : bio01, bio10, bio11, bio12, bio13, bio14, bio15, bio16, bio17, bio18, bio19, bio02, bio03, bio04, bio05, ... ## min values : -54.724354, -37.781418, -66.311249, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 9.131122, 0.000000, -29.686001, ... ## max values : 30.98764, 38.21617, 29.15299, 11191.00000, 2381.00000, 484.00000, 229.00169, 5284.00000, 1507.00000, 5282.00000, 4467.00000, 21.14754, 100.00000, 2363.84595, 48.08275, ... ``` --- # 3. Mapas estáticos ## Função `plot()` .pull-left[ ```r # plot plot(bioclim[[1:2]], col = viridis::viridis(10)) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-9-1.png" width="100%" height="100%" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## Função `plot()` ```r # diretorio dir.create(here::here("03_dados", "mapas")) # exportar mapa png(filename = here::here("03_dados", "mapas", "mapa_biomas.png"), width = 20, height = 20, units = "cm", res = 300) plot(biomas$geom, col = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3"), main = "Biomas do Brasil", axes = TRUE, graticule = TRUE) legend(x = -73, y = -20, pch = 15, cex = 1, pt.cex = 2.5, legend = biomas$name_biome, col = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3")) dev.off() ``` --- class: clear background-image: url(img/package_ggplot2.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [ggplot2](https://ggplot2.tidyverse.org/) --- background-image: url(img/stats_illustrations_ggplot2_obra_prima_pt.png) background-size: 500px background-position: 80% 80% # 3. Mapas estáticos ## **ggplot2**, **ggspatial** e **ggmap** ### Integrado ao **tidyverse**, possui uma sintaxe própria ### Principal pacote para **visualização de dados** no R ### Estrutura: `ggplot(...) +`<br> `aes(...) +`<br> `geom_(...) +`<br> `stats_(...) +`<br> `coord_(...) +`<br> `facet_(...) +`<br> `theme_(...)`<br> [ggplot2](https://ggplot2.tidyverse.org/), [@allison_horst](https://twitter.com/allison_horst) --- background-image: url(img/plot_ggplot.gif) background-size: 750px background-position: 50% 50% # 3. Mapas estáticos ## **ggplot2**, **ggspatial** e **ggmap** <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [Think About the Grammar of Graphics When Improving Your Graphs](https://medium.com/tdebeus/think-about-the-grammar-of-graphics-when-improving-your-graphs-18e3744d8d18) --- # 3. Mapas estáticos ## **ggplot2** e **ggspatial** .pull-left[ ```r # dados ggplot() + geom_sf(data = biomas) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-11-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **ggplot2** e **ggspatial** .pull-left[ ```r # cor e preenchimento ggplot() + geom_sf(data = biomas, color = "black", fill = NA) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-12-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **ggplot2** e **ggspatial** .pull-left[ ```r # cor e preenchimento ggplot() + geom_sf(data = biomas, aes(color = name_biome), fill = NA) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-13-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **ggplot2** e **ggspatial** .pull-left[ ```r # cor e preenchimento ggplot() + geom_sf(data = biomas, aes(fill = name_biome), color = NA) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-14-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **ggplot2** e **ggspatial** .pull-left[ ```r # definir cor ggplot() + geom_sf(data = biomas, aes(fill = name_biome), color = NA) + scale_fill_manual(values = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3")) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-15-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **ggplot2** e **ggspatial** .pull-left[ ```r # tema ggplot() + geom_sf(data = biomas, aes(fill = name_biome), color = NA) + scale_fill_manual(values = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3")) + theme_bw(base_size = 15) + theme(legend.title = element_text(size = 15, face = "bold"), legend.position = c(.2, .2), legend.background = element_rect(colour = "black")) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-16-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **ggplot2** e **ggspatial** .pull-left[ ```r # barra de escala e norte ggplot() + geom_sf(data = biomas, aes(fill = name_biome), color = NA) + scale_fill_manual(values = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3")) + theme_bw(base_size = 15) + theme(legend.title = element_text(size = 15, face = "bold"), legend.position = c(.2, .2), legend.background = element_rect(colour = "black")) + annotation_scale(location = "br") + annotation_north_arrow(location = "br", which_north = "true", pad_x = unit(0, "cm"), pad_y = unit(.5, "cm"), style = north_arrow_fancy_orienteering) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-17-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **ggplot2** e **ggspatial** .pull-left[ ```r # nomes e anotacoes ggplot(data = biomas) + aes(fill = name_biome) + geom_sf(color = "black") + scale_fill_manual(values = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3")) + theme_bw(base_size = 15) + theme(legend.title = element_text(size = 15, face = "bold"), legend.position = c(.2, .2), legend.background = element_rect(colour = "black")) + annotation_scale(location = "br") + annotation_north_arrow(location = "br", which_north = "true", pad_x = unit(0, "cm"), pad_y = unit(.5, "cm"), style = north_arrow_fancy_orienteering) + annotate(geom = "text", label = "CRS: SIRGAS2000/Geo", x = -38, y = -31, size = 2.5) + annotate(geom = "text", label = "Fonte: IBGE (2019)", x = -39, y = -32.5, size = 2.5) + labs(title = "Biomas do Brasil", fill = "Legenda", x = "Longitude", y = "Latitude") ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-18-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **ggplot2** e **ggspatial** .pull-left[ ```r # atribuicao map_biomas_ggplot2 <- ggplot(data = biomas) + aes(fill = name_biome) + geom_sf(color = "black") + scale_fill_manual(values = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3")) + theme_bw(base_size = 15) + theme(legend.title = element_text(size = 15, face = "bold"), legend.position = c(.2, .2), legend.background = element_rect(colour = "black")) + annotation_scale(location = "br") + annotation_north_arrow(location = "br", which_north = "true", pad_x = unit(0, "cm"), pad_y = unit(.5, "cm"), style = north_arrow_fancy_orienteering) + annotate(geom = "text", label = "CRS: SIRGAS2000/Geo", x = -38, y = -31, size = 2.5) + annotate(geom = "text", label = "Fonte: IBGE (2019)", x = -39, y = -32.5, size = 2.5) + labs(title = "Biomas do Brasil", fill = "Legenda", x = "Longitude", y = "Latitude") map_biomas_ggplot2 ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-19-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **ggplot2** e **ggspatial** .pull-left[ ```r # dados dem_rc_da <- raster::rasterToPoints(dem_rc) %>% tibble::as_tibble() head(dem_rc_da) ``` ] .pull-right[ ``` ## # A tibble: 6 × 3 ## x y srtm_27_17 ## <dbl> <dbl> <dbl> ## 1 -47.8 -22.2 859 ## 2 -47.8 -22.2 856 ## 3 -47.8 -22.2 856 ## 4 -47.8 -22.2 856 ## 5 -47.8 -22.2 853 ## 6 -47.8 -22.2 852 ``` ] --- # 3. Mapas estáticos ## **ggplot2** e **ggspatial** .pull-left[ ```r # plot map_dem_rc_ggplot2 <- ggplot() + geom_raster(data = dem_rc_da, aes(x = x, y = y, fill = srtm_27_17)) + geom_sf(data = rc_2020, col = "red", fill = NA, size = 1.3) + scale_fill_viridis_c() + coord_sf() + theme_bw(base_size = 15) + theme(legend.title = element_text(size = 15, face = "bold"), legend.position = c(.2, .2), legend.background = element_rect(colour = "black")) + annotation_scale(location = "br", pad_x = unit(.5, "cm"), pad_y = unit(.7, "cm"),) + annotation_north_arrow(location = "br", which_north = "true", pad_x = unit(.4, "cm"), pad_y = unit(1.3, "cm"), style = north_arrow_fancy_orienteering) + annotate(geom = "text", label = "CRS: WGS84/Geo", x = -47.51, y = -22.53, size = 3) + labs(title = "Elevação de Rio Claro/SP", fill = "Elevação (m)", x = "Longitude", y = "Latitude") map_dem_rc_ggplot2 ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-21-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **ggplot2** e **ggspatial** ```r # exportar ggsave( filename = here::here("03_dados", "mapas", "mapa_biomas_ggplot2.png"), plot = map_biomas_ggplot2, width = 20, height = 20, units = "cm", dpi = 300 ) ``` --- # 3. Mapas estáticos ## **ggplot2** e **ggspatial** ```r # exportar ggsave( filename = here::here("03_dados", "mapas", "mapa_dem_rc_rc_ggplot2.png"), plot = map_dem_rc_ggplot2, width = 20, height = 20, units = "cm", dpi = 300 ) ``` --- background-image: url(img/ggmap.jpg) background-size: 400px background-position: 50% 90% # 3. Mapas estáticos ## **ggmap** ```r # pacote # install.packages("ggmap") library(ggmap) # limite brasil <- c(left = -80, bottom = -35, right = -30, top = 5) rio_claro <- c(left = -47.67, bottom = -22.48, right = -47.46, top = -22.32) ``` <br><br><br><br><br><br><br><br> [ggmap](https://github.com/dkahle/ggmap) --- # 3. Mapas estáticos ## **ggmap** .pull-left[ ```r # plot get_stamenmap(bbox = brasil, maptype = "terrain", zoom = 5) %>% ggmap() ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-25-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **ggmap** .pull-left[ ```r # plot get_stamenmap(bbox = brasil, maptype = "toner", zoom = 5) %>% ggmap() ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-26-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **ggmap** .pull-left[ ```r # plot get_stamenmap(bbox = brasil, maptype = "toner-lite", zoom = 5) %>% ggmap() ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-27-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **ggmap** .pull-left[ ```r # plot get_stamenmap(bbox = brasil, maptype = "watercolor", zoom = 5) %>% ggmap() ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-28-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **ggmap** .pull-left[ ```r # plot get_stamenmap(bbox = rio_claro, maptype = "terrain", zoom = 12) %>% ggmap() ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-29-1.png" width="504" style="display: block; margin: auto;" /> ] --- class: clear background-image: url(img/package_tmap.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [tmap](https://mtennekes.github.io/tmap/) --- background-image: url(img/geo_tmap_article.png) background-size: 400px background-position: 50% 65% # 3. Mapas estáticos ## **tmap** ### Artigo <br><br><br><br><br><br><br><br><br><br><br><br><br> [Tennekes (2018)](https://www.jstatsoft.org/article/view/v084i06) --- background-image: url(img/geo_tmap_classic.png) background-size: 600px background-position: 80% 80% # 3. Mapas estáticos ## **tmap** ### Sintaxe baseada no **ggplot2** e na **Gramática dos Gráficos** ### Dois modos: **plot** (estáticos) e **visualização** (interativos) ### Estrutura: `tm_shape(...) +`<br> `tm_*(...) +`<br> `tm_facets(...) +`<br> `tm_layout(...)`<br> `tm_style(...)`<br> `tmap_arrange(...)`<br> `tm_mode(...)`<br> [tmap](https://mtennekes.github.io/tmap/) --- background-image: url(img/cover_geocompr.png) background-size: 230px background-position: 50% 65% # 3. Mapas estáticos ## **tmap** ### **Geocomputation with R (2019)** <br><br><br><br><br><br><br><br><br><br><br><br><br> [Lovelace et al. (2019)](https://geocompr.robinlovelace.net/adv-map.html) --- background-image: url(img/geo_tmap_book.png) background-size: 350px background-position: 50% 65% # 3. Mapas estáticos ## **tmap** ### **Elegant and informative maps with tmap** <br><br><br><br><br><br><br><br><br><br><br><br><br> [Tennekes & Nowosad (inacabado)](https://r-tmap.github.io/tmap-book/) --- background-image: url(img/geo_tmap_ggplot01.png), url(img/geo_tmap_ggplot02.png) background-size: 700px, 550px background-position: 50% 20%, 50% 90% # 3. Mapas estáticos ## **tmap** --- # 3. Mapas estáticos ## **tmap** .pull-left[ ```r # poligonos tm_shape(biomas) + tm_polygons() ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-30-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **tmap** .pull-left[ ```r # bordas tm_shape(biomas) + tm_borders() ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-31-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **tmap** .pull-left[ ```r # prenchimento tm_shape(biomas) + tm_fill() ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-32-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **tmap** .pull-left[ ```r # cores tm_shape(biomas) + tm_fill(col = "name_biome", title = "Legenda") ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-33-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **tmap** .pull-left[ ```r # definir cores tm_shape(biomas) + tm_fill(col = "name_biome", pal = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3"), title = "Legenda") ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-34-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **tmap** .pull-left[ ```r # gride coordenadas tm_shape(biomas) + tm_fill(col = "name_biome", pal = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3"), title = "Legenda") + tm_grid(lines = FALSE, labels.format = list(big.mark = ""), labels.rot = c(0, 90)) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-35-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **tmap** .pull-left[ ```r # barra de escala e norte tm_shape(biomas) + tm_fill(col = "name_biome", pal = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3"), title = "Legenda") + tm_grid(lines = FALSE, labels.format = list(big.mark = ""), labels.rot = c(0, 90)) + tm_compass() + tm_scale_bar() ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-37-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **tmap** .pull-left[ ```r # nomes tm_shape(biomas) + tm_fill(col = "name_biome", pal = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3"), title = "Legenda") + tm_grid(lines = FALSE, labels.format = list(big.mark = ""), labels.rot = c(0, 90)) + tm_compass() + tm_scale_bar() + tm_xlab("Longitude") + tm_ylab("Latitude") + tm_credits("CRS: SIRGAS2000/Geo", position = c(.58, .13)) + tm_credits("Fonte: IBGE (2019)", position = c(.58, .09)) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-38-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **tmap** .pull-left[ ```r # titulos tm_shape(biomas) + tm_fill(col = "name_biome", pal = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3"), title = "Legenda") + tm_graticules(lines = FALSE, labels.format = list(big.mark = ""), labels.rot = c(0, 90), labels.size = 1) + tm_compass(size = 3) + tm_scale_bar(size = 1) + tm_xlab("Longitude", size = 1.5) + tm_ylab("Latitude", size = 1.5) + tm_credits("CRS: SIRGAS2000/Geo", position = c(.58, .13), size = 1) + tm_credits("Fonte: IBGE (2019)", position = c(.58, .09), size = 1) + tm_layout(main.title = "Biomas do Brasil", main.title.position = c(.1, .95), main.title.size = 3, title.fontface = "bold", legend.frame = TRUE, legend.position = c("left", "bottom"), legend.title.fontface = "bold", legend.title.size = 2, legend.text.size = 1) ``` ].pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-39-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **tmap** .pull-left[ ```r # atribuicao map_biomas_tmap <- tm_shape(biomas) + tm_fill(col = "name_biome", pal = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3"), title = "Legenda") + tm_graticules(lines = FALSE, labels.format = list(big.mark = ""), labels.rot = c(0, 90), labels.size = 1) + tm_compass(size = 3) + tm_scale_bar(size = 1) + tm_xlab("Longitude", size = 1.5) + tm_ylab("Latitude", size = 1.5) + tm_credits("CRS: SIRGAS2000/Geo", position = c(.58, .13), size = 1) + tm_credits("Fonte: IBGE (2019)", position = c(.58, .09), size = 1) + tm_layout(main.title = "Biomas do Brasil", main.title.position = c(.1, .95), main.title.size = 3, title.fontface = "bold", legend.frame = TRUE, legend.position = c("left", "bottom"), legend.title.fontface = "bold", legend.title.size = 2, legend.text.size = 1) map_biomas_tmap ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-40-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **tmap** .pull-left[ ```r # plot map_dem_rc_tmap <- tm_shape(dem_rc) + tm_raster(title = "Legenda") + tm_shape(rc_2020) + tm_borders(col = "red", lwd = 2) + tm_grid(lines = FALSE, labels.format = list(big.mark = ""), labels.rot = c(0, 90)) + tm_compass() + tm_scale_bar() + tm_xlab("Longitude") + tm_ylab("Latitude") + tm_layout(legend.position = c("left", "bottom"), main.title = "Elevação Rio Claro/SP") map_dem_rc_tmap ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-41-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **tmap** .pull-left[ ```r # plot map_dem_rc_tmap <- tm_shape(dem_rc) + tm_raster(pal = wesanderson::wes_palette("Zissou1"), title = "Legenda") + tm_shape(rc_2020) + tm_borders(col = "red", lwd = 2) + tm_grid(lines = FALSE, labels.format = list(big.mark = ""), labels.rot = c(0, 90)) + tm_compass() + tm_scale_bar() + tm_xlab("Longitude") + tm_ylab("Latitude") + tm_layout(legend.position = c("left", "bottom"), main.title = "Elevação Rio Claro/SP") map_dem_rc_tmap ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-42-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **tmap** .pull-left[ ```r # plot map_dem_rc_tmap <- tm_shape(dem_rc) + tm_raster(pal = cptcity::cpt(pal = "gmt_GMT_dem4"), n = 20, title = "Legenda") + tm_shape(rc_2020) + tm_borders(col = "red", lwd = 2) + tm_grid(lines = FALSE, labels.format = list(big.mark = ""), labels.rot = c(0, 90)) + tm_compass(position = c("left", "bottom")) + tm_scale_bar(position = c("left", "bottom")) + tm_xlab("Longitude") + tm_ylab("Latitude") + tm_layout(legend.outside = TRUE, main.title = "Elevação Rio Claro/SP") map_dem_rc_tmap ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-43-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **tmap** ```r # exportar tmap::tmap_save(tm = map_biomas_tmap, filename = here::here("03_dados", "mapas", "mapa_biomas_tmap.png"), width = 20, height = 20, units = "cm", dpi = 300) ``` --- # 3. Mapas estáticos ## **tmap** ```r # exportar tmap::tmap_save(tm = map_dem_rc_tmap, filename = here::here("03_dados", "mapas", "mapa_dem_rc_tmap.png"), width = 20, height = 20, units = "cm", dpi = 300) ``` --- class: clear background-image: url(img/package_mapsf.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [mapsf](https://riatelab.github.io/mapsf/index.html) --- background-image: url(img/mapsf_types01.png), url(img/mapsf_types02.png) background-size: 350px, 350px background-position: 25% 90%, 75% 90% # 3. Mapas estáticos ## **mapsf** ```r # pacote # install.packages("mapsf") library(mapsf) # sintaxe mf_map(x, var, type) ``` <br><br><br><br><br><br><br><br><br> [mapsf](https://riatelab.github.io/mapsf/index.html) --- background-image: url(img/mapsf_map.png) background-size: 700px background-position: 50% 70% # 3. Mapas estáticos ## **mapsf** ## Layout <br><br><br><br><br><br><br><br><br><br><br><br> [mapsf](https://riatelab.github.io/mapsf/index.html) --- # 3. Mapas estáticos ## **mapsf** .pull-left[ ```r # plot mf_map(x = biomas) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-47-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **mapsf** .pull-left[ ```r # plot mf_map(x = biomas, var = "name_biome", type = "typo") ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-48-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **mapsf** .pull-left[ ```r # plot mf_map(x = biomas, var = "name_biome", type = "typo", pal = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3"), leg_title = "Biomas", leg_pos = c(-73, -15)) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-49-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **mapsf** .pull-left[ ```r # plot mf_map(x = biomas, var = "name_biome", type = "typo", pal = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3"), leg_title = "Biomas", leg_pos = c(-73, -15)) mf_title("Biomas do Brasil") mf_credits("IBGE, 2019") mf_scale() mf_arrow() ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-50-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **mapsf** .pull-left[ ```r # plot mf_init(x = biomas, theme = "dark") mf_map(x = biomas, var = "name_biome", type = "typo", pal = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3"), leg_title = "Biomas", leg_pos = c(-75, -15), add = TRUE) mf_title("Biomas do Brasil") mf_credits("IBGE, 2019") mf_scale() mf_arrow() ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-51-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **mapsf** .pull-left[ ```r # plot mf_theme(bg = "lightblue", fg = "gray20") mf_map(x = biomas, var = "name_biome", type = "typo", pal = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3"), leg_title = "Biomas", leg_pos = c(-73, -15)) mf_title("Biomas do Brasil") mf_credits("IBGE, 2019") mf_scale() mf_arrow() ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-52-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **mapsf** .pull-left[ ```r # plot mf_init(x = biomas, theme = "dark") mf_shadow(x = biomas, col = "gray10", add = TRUE) mf_map(x = biomas, var = "name_biome", type = "typo", pal = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3"), leg_title = "Biomas", leg_pos = c(-75, -15), add = TRUE) mf_title("Biomas do Brasil") mf_credits("IBGE, 2019") mf_scale() mf_arrow() ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-53-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **mapsf** .pull-left[ ```r # plot mf_init(x = biomas, theme = "dark") mf_shadow(x = biomas, col = "gray10", add = TRUE) mf_map(x = biomas, var = "name_biome", type = "typo", pal = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3"), leg_title = "Biomas", leg_pos = c(-75, -15), add = TRUE) mf_inset_on(x = "worldmap", pos = "topright") mf_worldmap(biomas, col = "#0E3F5C") mf_inset_off() mf_title("Biomas do Brasil") mf_credits("IBGE, 2019") mf_scale() mf_arrow() ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-54-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **mapsf** ```r # export mf_export(x = biomas, filename = here::here("03_dados", "mapas", "mapa_biomas_mapsf.png"), wi = 20, he = 20, un = "cm", res = 300) mf_init(x = biomas, theme = "dark") mf_shadow(x = biomas, col = "gray10", add = TRUE) mf_map(x = biomas, var = "name_biome", type = "typo", pal = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3"), leg_title = "Biomas", leg_pos = c(-70, -17), add = TRUE) mf_inset_on(x = "worldmap", pos = "topright") mf_worldmap(biomas, col = "#0E3F5C") mf_inset_off() mf_title("Biomas do Brasil") mf_credits("IBGE, 2019") mf_scale() mf_arrow() dev.off() ``` --- background-image: url(img/cover_time_series.png), url(img/time_series.png) background-size: 200px, 800px background-position: 10% 70%, 90% 70% # 3. Mapas estáticos ## **rasterVis** ```r # pacote # install.packages('rasterVis') library(rasterVis) ``` <br><br><br><br><br><br><br><br><br><br><br><br> [Lamigueiro (2018)](https://www.routledge.com/Displaying-Time-Series-Spatial-and-Space-Time-Data-with-R-Second-Edition/Lamigueiro/p/book/9781138089983), [Displaying time series, spatial and space-time data with R](https://oscarperpinan.github.io/bookvis/) --- # 3. Mapas estáticos ## **rasterVis** .pull-left[ ```r # plot levelplot(bioclim[[8:11]]) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-57-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **rasterVis** .pull-left[ ```r # plot levelplot(bioclim, layers = 1, margin = list(FUN = "median")) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-58-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **rasterVis** .pull-left[ ```r # plot levelplot(bioclim, layers = 4, margin = list(FUN = "median")) ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-59-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 3. Mapas estáticos ## **rasterVis** ```r # export png(filename = here::here("03_dados", "mapas", "mapa_bioclim_rastervis.png"), wi = 20, he = 20, un = "cm", res = 300) levelplot(bioclim, layers = 4, margin = list(FUN = "median")) dev.off() ``` --- background-image: url(img/geo_map_urban_animated.gif) background-size: 800px background-position: 50% 110% # 4. Mapas animados ## **Mapas animados** são utilizados para entender a mudanças espaciais e/ou no tempo --- # 4. Mapas animados ## Mudança dos estados do Brasil ao longo do tempo ```r # dados br_anos <- NULL for(i in c(1872, 1900, 1911, 1920, 1933, 1940, 1950, 1960, 1970, 1980, 1991, 2001, 2010, 2019, 2020)){ br_anos <- geobr::read_state(code_state = "all", year = i, showProgress = FALSE) %>% sf::st_geometry() %>% sf::st_as_sf() %>% dplyr::mutate(year = i) %>% dplyr::bind_rows(br_anos, .) } ``` -- ```r # numero de estados ao longo do tempo br_anos$year %>% table() ``` ``` ## . ## 1872 1900 1911 1920 1933 1940 1950 1960 1970 1980 1991 2001 2010 2019 2020 ## 21 21 22 22 22 24 28 29 28 28 29 27 27 27 27 ``` --- # 4. Mapas animados ## Mudança dos estados do Brasil ao longo do tempo .pull-left[ ```r # mapa facetado map_brasil_tmap <- tm_shape(br_anos) + tm_polygons() + tm_facets(by = "year", nrow = 4) map_brasil_tmap ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-63-1.png" width="504" style="display: block; margin: auto;" /> ] --- # 4. Mapas animados ## Mudança dos estados do Brasil ao longo do tempo .pull-left[ ```r # mapa animado map_brasil_tmap_ani <- tm_shape(br_anos) + tm_polygons() + tm_facets(along = "year", free.coords = FALSE) map_brasil_tmap_ani ``` ] .pull-right[ <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-64-1.png" width="504" style="display: block; margin: auto;" /> ``` ## =========== ``` <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-64-2.png" width="504" style="display: block; margin: auto;" /> ``` ## ===== ``` <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-64-3.png" width="504" style="display: block; margin: auto;" /> ``` ## ===== ``` <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-64-4.png" width="504" style="display: block; margin: auto;" /> ``` ## ====== ``` <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-64-5.png" width="504" style="display: block; margin: auto;" /> ``` ## ===== ``` <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-64-6.png" width="504" style="display: block; margin: auto;" /> ``` ## ===== ``` <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-64-7.png" width="504" style="display: block; margin: auto;" /> ``` ## ====== ``` <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-64-8.png" width="504" style="display: block; margin: auto;" /> ``` ## ===== ``` <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-64-9.png" width="504" style="display: block; margin: auto;" /> ``` ## ===== ``` <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-64-10.png" width="504" style="display: block; margin: auto;" /> ``` ## ====== ``` <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-64-11.png" width="504" style="display: block; margin: auto;" /> ``` ## ===== ``` <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-64-12.png" width="504" style="display: block; margin: auto;" /> ``` ## ===== ``` <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-64-13.png" width="504" style="display: block; margin: auto;" /> ``` ## ====== ``` <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-64-14.png" width="504" style="display: block; margin: auto;" /> ``` ## ===== ``` <img src="09_slides_intro_geoespacial_r_files/figure-html/unnamed-chunk-64-15.png" width="504" style="display: block; margin: auto;" /> ] --- background-image: url(img/geo_br_anos.gif) background-size: 500px background-position: 50% 70% # 4. Mapas animados ```r # exportar tmap::tmap_animation(tm = map_brasil_tmap_ani, filename = here::here("03_dados", "mapas", "mapa_dem_rc_tmap_ani.gif"), delay = 30) ``` --- # 5. Mapas interativos ## **Mapas interativos** são utilizados quando precisamos interagir <br> <iframe src="img/map_int.html" width="100%" height="400px" data-external="1"></iframe> --- class: clear background-image: url(img/package_tmap.png) background-size: 400px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [tmap](https://mtennekes.github.io/tmap/) --- # 5. Mapas interativos ## **tmap** ```r # mudar o modo de exibicao do tmap tmap::tmap_mode(mode = "view") map_biomas_tmap_int <- map_biomas_tmap map_biomas_tmap_int ``` <iframe src="img/geo_map_biomas_tmap.html" width="80%" height="400px" data-external="1"></iframe> --- # 5. Mapas interativos ## **tmap** ```r map_dem_rc_tmap_int <- map_dem_rc_tmap map_dem_rc_tmap_int ``` <iframe src="img/geo_map_tmap.html" width="100%" height="400px" data-external="1"></iframe> --- background-image: url(img/package_tmap.png) background-size: 300px background-position: 50% 90% # 5. Mapas interativos ## **tmap** ```r # exportar mapa tmap interativo tmap::tmap_save(tm = map_dem_rc_tmap_int, filename = here::here("dados", "mapas", "mapa_dem_rc_tmap_int.html")) ``` --- class: clear background-image: url(img/geo_mapview.gif) background-size: 450px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [mapview](https://r-spatial.github.io/mapview/) --- background-image: url(img/mapview_basic_small.png) background-size: 600px background-position: 50% 90% # 5. Mapas interativos ## **mapview** ### Display .pull-left[ ```r # pacote # install.packge("mapview") library(mapview) ``` ] .pull-right[ ] <br><br><br><br><br><br><br><br><br> [mapview](https://r-spatial.github.io/mapview/) --- # 5. Mapas interativos ## **mapview** ```r # plot map_dem_rc_mapview_int <- mapview::mapview(dem_rc, col.regions = viridis::viridis(100)) map_dem_rc_mapview_int ``` <iframe src="img/geo_map_mapview.html" width="100%" height="400px" data-external="1"></iframe> --- background-image: url(img/geo_mapview.gif) background-size: 350px background-position: 50% 90% # 5. Mapas interativos ## **mapview** ```r # exportar mapa tmap interativo mapview::mapshot(x = map_dem_rc_mapview_int, url = here::here("03_dados", "mapas", "mapa_dem_rc_mapview_int.html")) ``` --- class: clear background-image: url(img/package_leaflet.png) background-size: 450px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [leaflet](https://rstudio.github.io/leaflet/) --- background-image: url(img/leaflet.png), url(img/leaflet_r.png) background-size: 500px, 500px background-position: 5% 60%, 85% 50% # 5. Mapas interativos ## **leaflet** .pull-left[ ```r # pacote # install.packge("leaflet") library(leaflet) ``` ] .pull-right[ ] <br><br><br><br><br><br><br><br><br><br><br> [leafletjs](https://leafletjs.com/), [leaflet for R](https://rstudio.github.io/leaflet/) --- # 5. Mapas interativos ## **leaflet** ```r # paleta de cores pal <- colorNumeric(viridis::viridis(10), raster::values(dem_rc)) # mapa map_dem_rc_leaflet_int <- leaflet() %>% addProviderTiles("CartoDB.Positron") %>% addRasterImage(dem_rc, colors = pal, opacity = .8) %>% addLegend(pal = pal, values = raster::values(dem_rc), title = "Elevação (m)") %>% addPolygons(data = rc_2020, col = "red", fill = NA) map_dem_rc_leaflet_int ``` --- # 5. Mapas interativos ## **leaflet** <br> <iframe src="img/geo_map_leaflet.html" width="100%" height="400px" data-external="1"></iframe> --- background-image: url(img/package_leaflet.png) background-size: 350px background-position: 50% 90% # 5. Mapas interativos ## **leaflet** ```r # exportar mapa tmap interativo mapview::mapshot(x = map_dem_rc_leaflet_int, url = here::here("03_dados", "mapas", "mapa_dem_rc_leaflet_int.html")) ``` --- class: clear background-image: url(img/package_plotly.png) background-size: 450px background-position: 50% 50% <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> [plotly](https://plotly.com/r/) --- background-image: url(img/plotly.png) background-size: 700px background-position: 50% 80% # 5. Mapas interativos ## **plotly** .pull-left[ ```r # pacote # install.packge("plotly") library(plotly) ``` ] .pull-right[ ] <br><br><br><br><br><br><br><br><br><br><br> [plotly](https://plotly.com/r/) --- # 5. Mapas interativos ## **plotly** .pull-left[ ```r # plot map_rc_2020_plotly_int <- plot_geo(rc_2020) map_rc_2020_plotly_int ``` ] .pull-right[
] --- # 5. Mapas interativos ## **plotly** .pull-left[ ```r # plot map_rc_2020_plotly_int <- ggplotly( ggplot() + geom_sf(data = rc_2020) + theme_bw(base_size = 15)) map_rc_2020_plotly_int ``` ] .pull-right[
] --- # 5. Mapas interativos ## **plotly** .pull-left[ ```r # plot map_biomas_plotly_int <- ggplotly( ggplot(data = biomas) + aes(fill = name_biome) + geom_sf(color = "black") + scale_fill_manual(values = c("darkgreen", "orange", "orange4", "forestgreen", "yellow", "yellow3")) + theme_bw(base_size = 15) + annotate(geom = "text", label = "CRS: SIRGAS2000/Geo", x = -38, y = -31, size = 2.5) + annotate(geom = "text", label = "Fonte: IBGE (2019)", x = -39, y = -32.5, size = 2.5) + labs(title = "Biomas do Brasil", fill = "Legenda", x = "Longitude", y = "Latitude")) map_biomas_plotly_int ``` ] .pull-right[
] --- background-image: url(img/package_plotly.png) background-size: 350px background-position: 50% 90% # 5. Mapas interativos ## **plotly** ```r # exportar mapa tmap interativo mapview::mapshot(x = map_biomas_plotly_int, url = here::here("03_dados", "mapas", "mapa_dem_rc_leaflet_int.html")) ``` --- class: inverse, center, middle # E para finalizar, vamos editar dados vetoriais no R --- background-image: url(img/mapedit-leafpm01.gif), url(img/mapedit-leafpm02.gif) background-size: 400px, 400px background-position: 20% 85%, 80% 85% # 5. Mapas interativos ## **mapedit** ### Edições simples de pontos, linhas e polígonos ```r # pacote # install.packages("mapedit") library(mapedit) ``` <br><br><br><br><br><br><br><br><br><br> [mapedit](https://github.com/r-spatial/mapedit) --- # 5. Mapas interativos ## **mapedit** ```r # criar unesp <- mapedit::drawFeatures() unesp # editar unesp_editado <- mapedit::editFeatures(unesp) unesp_editado # mapa mapview::mapview(unesp_editado) ``` --- class: inverse, center, middle # Dúvidas? --- class: inverse, center, middle # Muito bem, finalizamos a parte teórico-prática... --- class: inverse, center, middle # Agora vem a parte do projeto, ou seja, onde vocês trabalham --- class: inverse, center, middle # Gostaria de agradecer todas e todos pela paciência e confiança <svg viewBox="0 0 504 512" style="height:1em;position:relative;display:inline-block;top:.1em;fill:white;" xmlns="http://www.w3.org/2000/svg"> <path d="M456 128c26.5 0 48-21 48-47 0-20-28.5-60.4-41.6-77.8-3.2-4.3-9.6-4.3-12.8 0C436.5 20.6 408 61 408 81c0 26 21.5 47 48 47zm0 32c-44.1 0-80-35.4-80-79 0-4.4.3-14.2 8.1-32.2C345 23.1 298.3 8 248 8 111 8 0 119 0 256s111 248 248 248 248-111 248-248c0-35.1-7.4-68.4-20.5-98.6-6.3 1.5-12.7 2.6-19.5 2.6zm-128-8c23.8 0 52.7 29.3 56 71.4.7 8.6-10.8 12-14.9 4.5l-9.5-17c-7.7-13.7-19.2-21.6-31.5-21.6s-23.8 7.9-31.5 21.6l-9.5 17c-4.1 7.4-15.6 4-14.9-4.5 3.1-42.1 32-71.4 55.8-71.4zm-160 0c23.8 0 52.7 29.3 56 71.4.7 8.6-10.8 12-14.9 4.5l-9.5-17c-7.7-13.7-19.2-21.6-31.5-21.6s-23.8 7.9-31.5 21.6l-9.5 17c-4.2 7.4-15.6 4-14.9-4.5 3.1-42.1 32-71.4 55.8-71.4zm80 280c-60.6 0-134.5-38.3-143.8-93.3-2-11.8 9.3-21.6 20.7-17.9C155.1 330.5 200 336 248 336s92.9-5.5 123.1-15.2c11.5-3.7 22.6 6.2 20.7 17.9-9.3 55-83.2 93.3-143.8 93.3z"></path></svg> --- class: clear, middle background-image: url(img/gif_frog.gif),url(img/gif_frogs.gif), url(img/package_xaringan.png) background-size: 250px, 500px, 130px background-position: 35% 50%, 90% 55%, 5% 86% ## Maurício Vancine <br><br> Contatos: <svg viewBox="0 0 512 512" style="height:1em;position:relative;display:inline-block;top:.1em;fill:#23373b;" xmlns="http://www.w3.org/2000/svg"> <path d="M502.3 190.8c3.9-3.1 9.7-.2 9.7 4.7V400c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V195.6c0-5 5.7-7.8 9.7-4.7 22.4 17.4 52.1 39.5 154.1 113.6 21.1 15.4 56.7 47.8 92.2 47.6 35.7.3 72-32.8 92.3-47.6 102-74.1 131.6-96.3 154-113.7zM256 320c23.2.4 56.6-29.2 73.4-41.4 132.7-96.3 142.8-104.7 173.4-128.7 5.8-4.5 9.2-11.5 9.2-18.9v-19c0-26.5-21.5-48-48-48H48C21.5 64 0 85.5 0 112v19c0 7.4 3.4 14.3 9.2 18.9 30.6 23.9 40.7 32.4 173.4 128.7 16.8 12.2 50.2 41.8 73.4 41.4z"></path></svg> [mauricio.vancine@gmail.com]() <svg viewBox="0 0 512 512" style="height:1em;position:relative;display:inline-block;top:.1em;fill:#23373b;" xmlns="http://www.w3.org/2000/svg"> <path d="M459.37 151.716c.325 4.548.325 9.097.325 13.645 0 138.72-105.583 298.558-298.558 298.558-59.452 0-114.68-17.219-161.137-47.106 8.447.974 16.568 1.299 25.34 1.299 49.055 0 94.213-16.568 130.274-44.832-46.132-.975-84.792-31.188-98.112-72.772 6.498.974 12.995 1.624 19.818 1.624 9.421 0 18.843-1.3 27.614-3.573-48.081-9.747-84.143-51.98-84.143-102.985v-1.299c13.969 7.797 30.214 12.67 47.431 13.319-28.264-18.843-46.781-51.005-46.781-87.391 0-19.492 5.197-37.36 14.294-52.954 51.655 63.675 129.3 105.258 216.365 109.807-1.624-7.797-2.599-15.918-2.599-24.04 0-57.828 46.782-104.934 104.934-104.934 30.213 0 57.502 12.67 76.67 33.137 23.715-4.548 46.456-13.32 66.599-25.34-7.798 24.366-24.366 44.833-46.132 57.827 21.117-2.273 41.584-8.122 60.426-16.243-14.292 20.791-32.161 39.308-52.628 54.253z"></path></svg> [@mauriciovancine](https://twitter.com/mauriciovancine) <svg viewBox="0 0 496 512" style="height:1em;position:relative;display:inline-block;top:.1em;fill:#23373b;" xmlns="http://www.w3.org/2000/svg"> <path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"></path></svg> [mauriciovancine](https://github.com/mauriciovancine) <svg viewBox="0 0 512 512" style="height:1em;position:relative;display:inline-block;top:.1em;fill:#23373b;" xmlns="http://www.w3.org/2000/svg"> <path d="M326.612 185.391c59.747 59.809 58.927 155.698.36 214.59-.11.12-.24.25-.36.37l-67.2 67.2c-59.27 59.27-155.699 59.262-214.96 0-59.27-59.26-59.27-155.7 0-214.96l37.106-37.106c9.84-9.84 26.786-3.3 27.294 10.606.648 17.722 3.826 35.527 9.69 52.721 1.986 5.822.567 12.262-3.783 16.612l-13.087 13.087c-28.026 28.026-28.905 73.66-1.155 101.96 28.024 28.579 74.086 28.749 102.325.51l67.2-67.19c28.191-28.191 28.073-73.757 0-101.83-3.701-3.694-7.429-6.564-10.341-8.569a16.037 16.037 0 0 1-6.947-12.606c-.396-10.567 3.348-21.456 11.698-29.806l21.054-21.055c5.521-5.521 14.182-6.199 20.584-1.731a152.482 152.482 0 0 1 20.522 17.197zM467.547 44.449c-59.261-59.262-155.69-59.27-214.96 0l-67.2 67.2c-.12.12-.25.25-.36.37-58.566 58.892-59.387 154.781.36 214.59a152.454 152.454 0 0 0 20.521 17.196c6.402 4.468 15.064 3.789 20.584-1.731l21.054-21.055c8.35-8.35 12.094-19.239 11.698-29.806a16.037 16.037 0 0 0-6.947-12.606c-2.912-2.005-6.64-4.875-10.341-8.569-28.073-28.073-28.191-73.639 0-101.83l67.2-67.19c28.239-28.239 74.3-28.069 102.325.51 27.75 28.3 26.872 73.934-1.155 101.96l-13.087 13.087c-4.35 4.35-5.769 10.79-3.783 16.612 5.864 17.194 9.042 34.999 9.69 52.721.509 13.906 17.454 20.446 27.294 10.606l37.106-37.106c59.271-59.259 59.271-155.699.001-214.959z"></path></svg> [mauriciovancine.github.io](https://mauriciovancine.github.io) <br><br><br><br><br> Slides criados via pacote [xaringan](https://github.com/yihui/xaringan) e tema [Metropolis](https://github.com/pat-s/xaringan-metropolis). Animação dos sapos por [@probzz](https://twitter.com/probzz/status/1367613720294170627).