municipalities <- read_sf(“C:/Users/user/Desktop/municipalities.shp”)

municipalities_SP <- municipalities %>% filter(UF == “SP”) municipalities_centroids <- municipalities_SP %>% st_centroid() municipalities_centroids %>% ggplot() + geom_sf()

SP_border <- municipalities_SP %>% st_union() SP_border %>% ggplot() + geom_sf()

SP_border %>% ggplot() + geom_sf() + geom_sf(data = municipalities_centroids) + theme_classic()

Second question

br_states <- municipalities %>% group_by(UF) %>% summarise(IDHM_mean=mean(IDHM_10))

br_states %>% ggplot() + geom_sf(aes(fill=IDHM_mean)) + theme_classic() + scale_fill_continuous(low=“blue”, high=“orange”)

second task

indigenous <- read_sf(“C:/Users/user/Desktop/bc250_Terra_Indigena_A.shp”) br_states %>% ggplot() + geom_sf() + geom_sf(data=indigenous, fill=“green”) Xingu <- indigenous %>% filter(nome==“Parque do Xingu”) %>% st_transform(4326) Gaucha <- municipalities %>% filter(NOME==“GAUCHA DO NORTE”) %>% st_transform(4326) Gaucha %>% ggplot() + geom_sf(fill=“purple”) + geom_sf(data = Xingu,fill=“red”, alpha=0.5)

intersection <- Gaucha %>% st_intersection(Xingu) intersection %>% ggplot() + geom_sf(fill=“Navy blue”)

Gaucha %>% ggplot() + geom_sf(fill=“pink”, alpha=0.5) + geom_sf(data=Xingu, fill=“yellow”, alpha=0.5) + geom_sf(data = intersection, fill=“Navy blue”)

intersection <- Gaucha %>% st_intersection(Xingu) intersection %>% ggplot() + geom_sf(fill = “dark green”)

Gaucha %>% ggplot() + geom_sf(fill+“yellow”, alpha=0.5) + geom_sf(data=Xingu, fill=“Pink”, alpha=0.5) + geom_sf(data = intersection, fill = “Navy blue”)

third task

Housing <- read_sf(“C:/Users/user/Desktop/MCMV_new.shp”) Housing_AC <- Housing %>% filter(UF==“AC”) br_states %>% filter(UF == “AC”) %>% ggplot() + geom_sf() + geom_sf(data = Housing_AC)

DISTANCE <- Housing_AC %>% st_transform(29189) %>% st_distance() %>% as.data.frame()

Housing_AC %>% st_transform(29189) %>% st_buffer(20000) %>% ggplot() + geom_sf(fill=“dark green”)

br_states %>% filter(UF == “AC”) %>% ggplot() + geom_sf() + geom_sf(data = (Housing_AC %>% st_transform(29189) %>% st_buffer(20000)), fill = “dark green”) + geom_sf(data = Housing_AC, color = “red”)

fourth task

mun_Housing_units <- municipalities %>% st_join(Housing) mun_Housing_units <- mun_Housing_units %>% group_by(COD_MUN,NOME) %>% summarise(UH=sum(UH,na.rm=T)) %>% ungroup()

mun_Housing_units %>% arrange(-UH) %>% slice(1) %>% pull(NOME)

mun_Housing_units %>% ggplot() + geom_sf(aes(fill = UH), col=NA) + scale_fill_gradient(low=“#ccece6”, high=“dark green”, trans=“log”)+ theme_classic()