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_sf <- municipalities %>% filter(UF=="SP")
municipalities_centroids <- municipalities_sf %>% st_centroid()
municipalities_centroids %>% ggplot() + geom_sf()
SP_border <- municipalities_sf %>% st_union()
SP_border %>% ggplot() + geom_sf()
4. Plot SP centroids and SP border together
SP_border %>% ggplot() + geom_sf() +
geom_sf(data=municipalities_centroids) +
theme_classic()
## Task Two What is the mean Human Development Index of municipalities
in each state of Brazil?
HDI is a variable from municipalities data set
Calculate mean HDI by state
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="red",high="green")
## Task Three Produce a polygon/shapefile mapping the area of the
municipality ‘Gaucha do Norte’ that is in the indigenous territory
“Parque do Xingu”.
indigenous <- read_sf("BC250_Terra_Indigena_A/BC250_Terra_Indigena_A.shp") %>% st_transform(4326)
br_states %>% ggplot() +
geom_sf() +
geom_sf(data=indigenous, fill="red")
2. Create a shapefile for Gaucha do Norte e Xingu
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="red") +
geom_sf(data=Xingu, fill="blue", alpha=0.5)
interaction <- Gaucha %>% st_intersection(Xingu)
## Warning: attribute variables are assumed to be spatially constant throughout
## all geometries
interaction %>% ggplot() + geom_sf(fill="dark green")
Gaucha %>% ggplot() +
geom_sf(fill="red", aplha = 0.5) +
geom_sf(data=Xingu, fill="blue", alpha=0.5) +
geom_sf(data = interaction, fill = "black")
## Warning in layer_sf(geom = GeomSf, data = data, mapping = mapping, stat = stat,
## : Ignoring unknown parameters: `aplha`
st_area(interaction)
## 8109249396 [m^2]
In the state of Acre (AC), which two social housing (MCMV) projects are closest to each other? Create a 10km buffer around each housing 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) %>%
summarise(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 %>% ggplot() +
geom_sf(aes(fill=UH) , col=NA) +
scale_fill_gradient(low="#ccece6",high="dark green", trans="log") +
theme_classic()
## Warning in scale_fill_gradient(low = "#ccece6", high = "dark green", trans =
## "log"): log-2.718282 transformation introduced infinite values.
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.