1
I created a map of SP and MG states using brazilmaps()
.
On this map I filled some cities with values.
However, I would like to make the border of states appear on Plot.
How do I do that?
Follow what I’m trying to.
library(brazilmaps)
library(maptools)
library(RColorBrewer)
library(tidyverse)
# Definindo paleta de cores ----
createColors <- colorRampPalette(c("yellow","red","darkgreen"))
# Definindo cidades e estados ----
cidades_sp_mg <- get_brmap(geo = "City", geo.filter = list(State = c(31,35))
,class = "SpatialPolygonsDataFrame")
estados_sp_mg <- get_brmap(geo = "State", geo.filter = list(State = c(31,35))
,class = "SpatialPolygonsDataFrame")
# Criando Mapa ----
load(file="dados/data.Rdata")
# Agrupa por municipio, conta quantas coop. cada municipio tem
dScore_data <- data %>% group_by(cod_municipio_ibge) %>% count()
# Gera mapa das cidades
mapa_data <- plot_brmap(cidades_sp_mg,
data_to_join = dScore_data,
join_by = c("City" = "cod_municipio_ibge"),
var = "n"
)
mapa2_data <- plot_brmap(estados_sp_mg,
data_to_join = dScore_data,
join_by = c("State" ="cod_uf"),
var = "n"
)
MinhasCores_data <- createColors(4)
png("dados/Cities.png", width = 800, height = 600)
print(mapa_data) +
scale_fill_gradientn(colours=MinhasCores_data,name="Qtd.", na.value = "lightgray") +
labs(title="Cities",caption = "Font") +
theme(legend.title = element_text(face="bold"),title = element_text(face="bold"),
plot.title = element_text(hjust = 0.5,size=20),
plot.caption = element_text(hjust = 0.5,size = 10))
+ plot(mapa2_data)
dev.off()
With the + plot(mapa2_data)
gives error. But without this command, states are generated and cities filled normally, without state borders.