Produce a map showing the centroids of each municipality in just the state of Säo Paulo, and add the outer boundary of Säo Paulo state.
municipalities <- read_sf("municipalities/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)
What is the mean Human Development Index of municipalities in each state of Brazil?
Remember that HDI is a variable from municipalities data set. Open table to set it.
Calculate mean HDI by state
br_states <- municipalities %>% group_by(UF) %>% summarise(IDHM_mean=mean(IDHM_10))
view(br_states)
br_states %>% ggplot() +
geom_sf(aes(fill=IDHM_mean))+
theme_classic() +
scale_fill_continuous(low="red",high="green")
produce a polyline/shapefile mapping the area of the municipality ‘Gaucha do Notre’ that is in the indigenous territory “Parque de xinqgu”
indeginous <- read_sf("BC250_Terra_Indigena_A/BC250_Terra_Indigena_A.shp") %>% st_transform(4326)
br_states %>% ggplot() +
geom_sf() +
geom_sf(data = indeginous, fill="red")
Xingu <- indeginous %>% filter(nome=="Parque do Xingu") %>% st_transform(4326)
Gaucha <- municipalities %>% filter(NOME=="GAUCHA DO NORTE") %>% st_transform(4326)
3 Plot the shape files to see the overlap
Gaucha %>% ggplot() +
geom_sf(fill="red") +
geom_sf(data=Xingu, fill="blue", alpha=0.5)
4 create shapefile for intersction and plot it
intersection <- Gaucha %>% st_intersection(Xingu)
intersection %>% ggplot() + geom_sf(fill="dark green")
5 plot all together
Gaucha %>% ggplot() +
geom_sf(fill="red", alpha=0.5) +
geom_sf(data=Xingu, fill="blue", alpha=0.5) +
geom_sf(data = intersection, fill = "black")
you can calcualte the intersection area
st_area(intersection)
## 8109249396 [m^2]
In the state of Acre (AC), which two social housing (MCMV) projects are closest to each other? Create 20km buffer around each housinh project.
Housing <- read_sf("MCMV_new/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")
Across Brazil, which municipalities have the lowest and highest number of MCMV housing units (UH) in its territory? Create a map of the distribution of total housing units by municipality.
mun_Housing_units <- municipalities %>% st_join(Housing)
mun_Housing_units <- mun_Housing_units %>%
group_by(COD_MUN, NOME) %>%
summarize(UH=sum(UH, na.rm = T)) %>%
ungroup()
## `summarise()` has grouped output by 'COD_MUN'. You can override using the
## `.groups` argument.
mun_Housing_units %>% arrange(-UH) %>% slice(1) %>%pull(NOME)
## [1] "RIO DE JANEIRO"
mun_Housing_units %>% arrange(UH) %>% slice(1) %>%pull(NOME)
## [1] "CABIXI"
mun_Housing_units %>% ggplot()+
geom_sf(aes(fill=UH), col=NA) +
scale_fill_gradient(low="#ccece6", high="dark green", trans="log")+
theme_classic()
## Warning: Transformation introduced infinite values in discrete y-axis