forked from wdartora/mapa_rs_ufrgs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopia_script.R
More file actions
77 lines (47 loc) · 2.17 KB
/
copia_script.R
File metadata and controls
77 lines (47 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Carregando os pacotes----
library(maptools)
library(spdep)
library(cartography)
library(tmap)
library(leaflet)
library(dplyr)
library(rgdal)
library(dplyr)
library(RColorBrewer)
#testando comentário
# Importando shapefile (mapa do Brasil)----
shp <- readOGR("C:\\Users\\00192923\\Desktop\\shape_file", stringsAsFactors=FALSE, encoding="UTF-8")
class(shp$CD_GEOCMU)
dados$CD_GEOCMU <- as.data.frame(shp$CD_GEOCMU)
vetor <- seq(0.23, 4.17, 0.34)
dados$DADOS <- sample(x = vetor, size = 499, replace = TRUE)
dados$DADOS <- replace(dados$DADOS, dados$`shp$NM_MUNICIP`=="LAGOA DOS PATOS", NA)
# Importando códigos do IBGE e adicionando ao dataset----
# ibge <- read.csv("D:/Ewerton/Mapas R/Dados\\estadosibge.csv", header=T,sep=",")
#
# pg <- merge(pg,ibge, by.x = "Location", by.y = "Unidade.da.Federação")
# Fazendo a junção entre o dataset e o shapefile----
dados_mapa <- merge(shp,dados, by.x = "NM_MUNICIP", by.y = "shp$NM_MUNICIP")
#Tratamento e transformação dos dados----
proj4string(dados_mapa) <- CRS("+proj=longlat +datum=WGS84 +no_defs") #adicionando coordenadas geográficas
Encoding(dados_mapa$NM_MUNICIP) <- "UTF-8"
#brasileiropg$Score[is.na(brasileiropg$Score)] <- 0 #substituindo NA por 0
# Gerando o mapa----
?colorNumeric
pal <- colorNumeric(palette = "Spectral", domain = dados_mapa$DADOS, reverse = TRUE) #cores do mapa
municipio_popup <- paste0("<strong>Municipio: </strong>",
dados_mapa$NM_MUNICIP,
"<br><strong>% prevalência de SCA: </strong>",
dados_mapa$DADOS)
mapa_sca <- leaflet(data = dados_mapa) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(fillColor = ~pal(dados_mapa$DADOS),
fillOpacity = 0.2,
color = "#BDBDC3",
weight = 1,
popup = municipio_popup) %>%
addLegend("bottomright", pal = pal, values = ~dados_mapa$DADOS,
title = "Incidência de SCA",
opacity = 1)
htmlwidgets::saveWidget(mapa_sca, "C:\\Users\\00192923\\Desktop\\shape_file\\Projeto_UFRGS\\Projeto_William.html",
selfcontained = TRUE)