7
Good morning,
I’m trying to create a Brazilian map that presents the amount of cooperatives present in each city.
I have a table with the IBGE code of the municipalities and the amount of Coop.
I got the shapefile from the IBGE website:
https://downloads.ibge.gov.br/downloads_geociencias.htm
and I tried to follow that example:
https://dataficacao.wordpress.com/2017/02/21/criando-mapa-brasil-r/
However, when applied to municipalities, the R is processing for a few minutes and suddenly hangs. What can be?
One more question, I would like to leave the division by states and regions appearing. It is possible?
Below are lines of code:
shpmun <- readOGR("G:/Lupa Econômica/Ricardo/Qtd de
Coop/dados/MAPA/BRMUE250GC_SIR.shp", stringsAsFactors=FALSE, encoding="UTF-8")
load('G:/Lupa Econômica/Ricardo/Qtd de
Coop/dados/Rais_Coop_Estb_2016.RData')
Rais_Coop_Estb_2016$Cont <- as.numeric(c(1))
Rais_Coop_Estb_2016mapamun <- Rais_Coop_Estb_2016 %>% group_by(Município)
%>% mutate(cumsum = cumsum(Cont))
Rais_Coop_Estb_2016mapamun <- Rais_Coop_Estb_2016mapamun %>%
group_by(Município) %>% summarise(Score= max(cumsum))
Rais_Coop_Estb_2016mapamun <- as.data.frame(Rais_Coop_Estb_2016mapamun)
brasileiropgmun <- merge(shpmun,Rais_Coop_Estb_2016mapamun, by.x =
"CD_GEOCMU", by.y = "Município")
proj4string(brasileiropgmun) <- CRS("+proj=longlat +datum=WGS84 +no_defs")
#adicionando coordenadas geográficas
Encoding(brasileiropgmun$NM_MUNICIP) <- "UTF-8"
brasileiropgmun$Score[is.na(brasileiropgmun$Score)] <- 0
display.brewer.all()
pal <- colorBin("YlGn",domain = NULL,n=20) #cores do mapa
state_popupmun <- paste0("<strong>Município: </strong>",
brasileiropgmun$NM_MUNICIP,
"<br><strong>Pontos: </strong>",
brasileiropgmun$Score)
leaflet(data = brasileiropgmun) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(fillColor = ~pal(brasileiropgmun$Score),
fillOpacity = 0.8,
color = "#BDBDC3",
weight = 1,
popup = state_popupmun) %>%
addLegend("bottomright", pal = pal, values = ~brasileiropgmun$Score,
title = "Pontos Conquistados",
opacity = 1)
** The legend isn’t showing up either.
See if this link helps: <https://answall.com/questions/315747/como-inser-uma-legenda-em-um-mapa-no-r-com-o-package-rcolorbrewer>
– neves
Thank you very much, helped in parts ! In my Coop base I have: each line a Coop and each Coop is connected to a municipality. How would you group them and represent them on the map? Ex: the more dark the color, the greater the number of Coop in the region?
– RxT
I tried using Rais_coop_estb_2016mapamun <- Rais_coop_estb_2016%>% group_by(Municipality) %>% mutate(cumsum = cumsum(Cont)) Rais_coop_estb_2016mapamun <- Rais_coop_estb_2016mapamun%>% group_by(Municipality) %>% summarise(Score= max(cumsum)) Rais_coop_estb_2016mapamun <- as.data.frame(Rais_coop_estb_2016mapamun) but how to add this in the example ?
– RxT