I have a shapefile with 7 regions. I have an excel file with data about reptiles in these 7 regions. I merged this shapefile with excel.
Using ggplot I tried to generate facet_wrap() from nome_popular, however the rest of the polygon parts were omitted in each facet created.
My tentative code
shapefile: https://drive.google.com/file/d/1I1m9lBX69zjsdGBg2zfpii5H4VFYE1_0/view?usp=sharing
# load data.frame
serpentes <- read_excel("E:/22-serpentes_cg/R/serpentes_cg_finall.xlsx")
# filer data.frame
total_especies <- serpentes %>%
rename(regiao_cg = REGIAO_CG) %>%
group_by(
especie, nome_popular,
regiao_cg
) %>%
summarise(Total_esp = sum(quant))
# load shapefile
regiao <- sf::st_read("E:/22-serpentes_cg/geo/regioes_urbanas.shp") %>%
rename(regiao_cg = REGIAO_CG)
# join shapefile and excel
total_especies_shp <- dplyr::left_join(regiao, total_especies, by = "regiao_cg")
# map facet_warp
p_total_especies_shp <- ggplot(
na.omit(total_especies_shp),
aes(fill = factor(Total_esp))
) +
geom_sf() +
scale_fill_brewer(
palette = "Spectral", na.value = "grey", direction = -1,
"Total de\nSepertens Regatadas"
) +
facet_wrap(~nome_popular)
p_total_especies_shp
output incomplete
OBS EDIT
I tried @stefan's answer which partly worked, but generated a facet called "NA" bad.
new code:
p_total_especies_shp <- ggplot(total_especies_shp)+
geom_sf(data=regiao)+
geom_sf(aes(fill=factor(Total_esp)))+
scale_fill_brewer(
palette = "Spectral", na.value = "grey", direction = -1,
"Total de\nSepertens Regatadas")+
facet_wrap(~nome_popular)
p_total_especies_shp



