Hi, you again! Thank you for helping me. I understand everything you explained, including the code! But mine was wrong because of an empty neighborhood (just like what happened in the SAR Model). So, thanks to your help back there, I was able to work around this problem and fix the empty neighborhood error!
--------- Packages ---------
setwd("C:/Users/lucas/Desktop/Relatório Final FAPESP")
if (!require("geobr")) install.packages("geobr")
if (!require("tidyverse")) install.packages("tidyverse")
if (!require("ggspatial")) install.packages("ggspatial")
if (!require("magrittr")) install.packages("magrittr")
if (!require("lubridate")) install.packages("lubridate")
if (!require("readxl")) install.packages("readxl")
library(readxl)
library(geobr)
library(tidyverse)
library(ggspatial)
library(magrittr)
library(lubridate)
--------- Shape File ---------
SP.Municipios <- read_municipality(code_muni = "all",year=2019) %>%
filter(code_state == 35) %>%
select(-c("code_state","abbrev_state","code_region","name_region","name_state")) %>%
rename(Municípios = name_muni) %>%
ggplot(SP.Municipios) +
geom_sf()
--------- Data Set ---------
Data.Raw <- read_excel("Base.xlsx")
Total.Data <- full_join(Data.Raw, SP.Municipios, by = "Municípios")
Data <- Total.Data[c(-644,-645),] %>%
rename(Incid = Incidência da COVID-19)
Data <- st_as_sf(Data)
--------- Clusters Analysis ---------
if (!require("remotes")) install.packages("remotes")
library(remotes)
remotes::install_github("Josiahparry/sfweight")
if (!require("sf")) install.packages("sf")
if (!require("dplyr")) install.packages("dplyr")
if (!require("ggplot2")) install.packages("ggplot2")
library(sf)
library(dplyr)
library(ggplot2)
library(sfweight)
if (!require("readr")) install.packages("readr")
if (!require("rgdal")) install.packages("rgdal")
if (!require("spdep")) install.packages("spdep")
if (!require("spatialreg")) install.packages("spatialreg")
library(readr)
library(rgdal)
library(spdep)
library(spatialreg)
#This will cause an error.
wrong <- Data %>%
poly2nb() %>%
nb2listw()
problematic <- Data %>%
poly2nb() %>%
card() %>%
magrittr::equals(0) %>%
which()
corrected_Data <- Data[-problematic, ]
shape_lisa.SP <- corrected_Data %>%
mutate(nb = st_neighbors(geom),
wts = st_weights(nb),
lag_Incid = st_lag(Incid, nb, wts),
lisa = categorize_lisa(Incid, lag_Incid))
ggplot(data = shape_lisa.SP) +
geom_sf(aes(fill = lisa))
--------- / --------- / --------- / --------- / ---------
Would I be able to modify the caption, from that, adding the "not significant" to p<0.05? Because this map is a little visually polluted. Something just like that:

If it's not possible, that's totally fine. You helped me a lot and I am again extremely grateful for that.
Virtual hugs from Brazil,
Lucas.