I made a map of Brazilian cities using plot_brmap()
and I want to show the state border.
But I don't know how to do it. I have been trying to fill the mapa2_data
(state map) with transparent color and plot with mapa_data
(city map).
But it's not working.
What I have been trying:
library(brazilmaps)
library(maptools)
library(RColorBrewer)
# 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 - Cooxupé e Cocapec ----
load(file="dados/data.Rdata")
# Agrupa por razao social e 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"
)
dScore_data$code_state <- as.numeric(dScore_datac$code_state)
mapa2_data <- plot_brmap(estados_sp_mg,
data_to_join = dScore_data,
join_by = c("State" = "code_state"),
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()