I have a MAP created with this code, and this file in MSEXCEL (LINK TO THE CORRESPONDING FILE): Add an upgraded legend to map ggplot:
This map contains information about qualifications of languajes by municipalities(MUNICIPIO), and thos municipalities were grouped in NEW_CD.
library(tidyverse)
library(brazilmaps)
library(ggspatial)
library(dplyr)
library(data.table)
library(hablar)
library(readxl)
library(stringi)
library(grid)
library(mapproj)
library(rgdal)
library(ggsn)
data <- read_excel("2005.xls") %>%
mutate(MUNICIPIO = padroniza_texto(MUNICIPIO)) %>%
inner_join(pop2017 %>% mutate(nome_mun = padroniza_texto(nome_mun)), by = c("MUNICIPIO" = "nome_mun"))
<br>dados_para_mapa$mun <- replace(dados_para_mapa$mun, dados_para_mapa$mun < 3500000, NA)
<br>dados_para_mapa$mun <- replace(dados_para_mapa$mun, dados_para_mapa$mun > 4000000, NA)
<br>dados_para_mapa<-dados_para_mapa[!is.na(dados_para_mapa$mun), ]
<br>dados_para_mapa <- read_excel("2005.xls") %>%
mutate(MUNICIPIO = padroniza_texto(MUNICIPIO)) %>%
inner_join(pop2017 %>% mutate(nome_mun = padroniza_texto(nome_mun)), by = c("MUNICIPIO" = "nome_mun"))
<br>dados_para_mapa$mun <- replace(dados_para_mapa$mun, dados_para_mapa$mun < 3500000, NA)
<br>dados_para_mapa$mun <- replace(dados_para_mapa$mun, dados_para_mapa$mun > 4000000, NA)
<br>dados_para_mapa<-dados_para_mapa[!is.na(dados_para_mapa$mun), ]
<br>dados_para_mapa %>% find_duplicates(MUNICIPIO)
get_brmap("City", geo.filter = list(State = 35)) %>%
<br> left_join(dados_para_mapa, c("City" = "mun")) %>%
<br> group_by(NEW_CD) %>%
<br> summarise(
<br> VARIAVEL = mean(COEFICIENTE_DE_DETECCAO)) %>%
<br> ggplot() +
<br> geom_sf(aes(fill = VARIAVEL))+
<br> # change color pallet
<br> scale_fill_continuous(low = "#ffffff", high = "#60DCCC") +
<br> #Escale
<br> annotation_scale(location = "bl", width_hint = 0.5) +
<br> annotation_north_arrow(location = "bl", which_north = "true",
<br> pad_x = unit(0.5, "in"), pad_y = unit(0.5, "cm"),
<br> style = north_arrow_fancy_orienteering) +
<br> # legend title
<br> theme(legend.title = element_text(colour="black", size=15, face="bold")) +
<br> # legend labels
<br> theme(legend.text = element_text(colour="black", size=15, face="bold")) +
<br> # erase cartesian system in background
<br> theme(panel.grid = element_line(colour = "transparent"),
<br> panel.background = element_blank(),
<br> axis.text = element_blank(),
<br> axis.ticks = element_blank())
<br>
as result, I have a map with a simple legend,
but i need to upgrade this legend showing the mean and standar error for each grouping [group_by(NEW_CD)] instead each color box associated with each mean and the number of observations into each group [scale_fill_continuous(low = "#ffffff", high = "#60DCCC")].
I hope to be clear and be helped. Map annotation needs to be clear.
Advance Thank you very much.