Last active
August 29, 2021 14:23
-
-
Save DATAUNIRIO/4dfa0d238bb10a9cd49c818e2611f02b to your computer and use it in GitHub Desktop.
Mapas com geobr e geom_sf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(readxl) | |
library(dplyr) | |
library(ggplot2) | |
# Import ----------------------------------------------------------------------- | |
dados_brutos <- read_excel("C:/Users/Hp/Desktop/Base_de_dados-master/BasesEstados.xlsx") | |
mapa_estados <- geobr::read_state() | |
#plot(mapa_estados) | |
# Tidy ------------------------------------------------------------------------- | |
dados_brutos <- dados_brutos %>% rename(code_state=Codigo) | |
dados_brutos$code_state<- as.numeric(dados_brutos$code_state) | |
names(dados_brutos) | |
dados_mapa <- mapa_estados %>% left_join(dados_brutos) | |
# Visualize -------------------------------------------------------------------- | |
ggplot() + | |
geom_sf(data=dados_mapa, aes(fill=IDH)) + | |
scale_fill_distiller(palette = "Oranges",direction = 1, name="IDH", limits = c(0.6,1)) | |
ggplot() + | |
geom_sf(data=dados_mapa, aes(fill=IDH), color= "black", size=.15) + | |
labs(subtitle="Mapa 1 - IDH por UF", size=10) + | |
geom_sf_text(data=dados_mapa,aes(label = abbrev_state), size=2, color= "black")+ | |
scale_fill_distiller(palette = "Oranges",direction = 1, name="IDH", limits = c(0.6,1)) + | |
theme_minimal() | |
ggplot() + | |
geom_sf(data=dados_mapa, aes(fill=Energia), color= "black", size=.15) + | |
labs(subtitle="Mapa 2 ", size=10) + | |
geom_sf_text(data=dados_mapa,aes(label = abbrev_state), size=2, color= "black")+ | |
scale_fill_distiller(palette = "Reds",direction = 1, name="% da população", limits = c(90,100))+ | |
theme_minimal() | |
ggplot() + | |
geom_sf(data=dados_mapa, aes(fill=Banheiro), color= "black", size=.15) + | |
labs(subtitle="Mapa 3 - % da população em domicílios com banheiro e água encanada por estado e DF", size=10) + | |
geom_sf_text(data=dados_mapa,aes(label = abbrev_state), size=2, color= "black")+ | |
scale_fill_distiller(palette = "Greens",direction = 1, name="% da população", limits = c(40,100)) + | |
theme_minimal() | |
ggplot() + | |
geom_sf(data=dados_mapa, aes(fill=Agua), color= "black", size=.15) + | |
labs(subtitle="Mapa 4 - % da população em domicílios com água encanada por estado e DF", size=10) + | |
geom_sf_text(data=dados_mapa,aes(label = abbrev_state), size=2, color= "black")+ | |
scale_fill_distiller(palette = "Blues",direction = 1, name="% da população", limits = c(75,100)) + | |
theme_minimal() | |
#------------------------------------------------------------------------------------------------------------- | |
#------------------------------------------------------------------------------------------------------------- | |
#------------------------------------------------------------------------------------------------------------- | |
# https://r-spatial.github.io/mapview/ | |
#------------------------------------------------------------------------------------------------------------- | |
#------------------------------------------------------------------------------------------------------------- | |
#------------------------------------------------------------------------------------------------------------- | |
library(leaflet) | |
library(leaflet.providers) | |
library(leaflet.extras) | |
providers <- get_providers() | |
leaflet_map <- dados_mapa %>% | |
leaflet() %>% | |
addTiles(urlTemplate = providers$providers_details$OpenTopoMap$url) %>% | |
addTiles(urlTemplate = providers$providers_details$OpenRailwayMap$url) %>% | |
setView(-55,-13, 5) %>% | |
addHeatmap(~lng, ~lat, intensity = .001, radius = 20, blur = 10) %>% | |
addMarkers(~lng, ~lat, data = sample_n(da, 100)) %>% | |
addDrawToolbar() %>% | |
addMeasurePathToolbar() %>% | |
addControlGPS( | |
options = gpsOptions( | |
position = "topleft", | |
activate = TRUE, | |
autoCenter = TRUE, | |
maxZoom = 60, | |
setView = TRUE | |
) | |
) | |
leaflet_map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment