Atividade 4 - Mapas

Author

Luana

Chegou a hora de fixar o nosso aprendizado sobre a aula de mapas!

Para isso, vamos fazer dois exercícios independentes e usar diferentes conjunto de dados do tidytuesday (https://github.com/rfordatascience/tidytuesday)

Exercício 1

Utilizando qualquer recurso apresentado em aula, faça um mapa destacando ou mostrando o estado e município que você nasceu.

library(ggmap)
Carregando pacotes exigidos: ggplot2
ℹ Google's Terms of Service: <https://mapsplatform.google.com>
ℹ Please cite ggmap if you use it! Use `citation("ggmap")` for details.
library(maps)
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.2     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ lubridate 1.9.2     ✔ tibble    3.2.1
✔ purrr     1.0.1     ✔ tidyr     1.3.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
✖ purrr::map()    masks maps::map()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
library(readr)
library(ggplot2)
library(geobr)
Loading required namespace: sf
datasets <- list_geobr() 


muni_SC <- read_municipality(code_muni = "SC",
                             year=2020, showProgress = FALSE)
Using year 2020
sbs<- read_municipality(code_muni = 4215802, 
                 year=2020, showProgress = FALSE)
Using year 2020
state_all<-read_state(code_state = "all",  year=2020, showProgress = FALSE)
Using year 2020
Problem connecting to data server. Please try again in a few minutes.
muni_all<-read_municipality(code_muni = "all",
                            year=2020, showProgress = FALSE)
Using year 2020
Problem connecting to data server. Please try again in a few minutes.
ggplot() + 
  geom_sf(data=muni_all, fill="lightyellow", color="lightgray", show.legend = FALSE) +
   geom_sf(data=muni_SC, fill="lightyellow", color="black", show.legend = FALSE) +
  geom_sf(data=sbs , fill="orange", color="orange", show.legend = FALSE)+
  coord_sf(xlim= c(-55,-48), ylim=c(-29.5,-26))+
  labs(title="São Bento do Sul/SC")+
  theme_classic()+
  theme(legend.position = c(0.8,0.9), legend.background = element_blank(), legend.text=element_text(size=10),
        legend.title = element_blank(),
        legend.key.size = unit(0.4, "cm"),
        panel.grid.major = element_line(color = "gray", linetype = "dashed", size = 0.5), 
        panel.background = element_rect(fill = "lightblue"),
        axis.title = element_blank())
Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
ℹ Please use the `linewidth` argument instead.

Exercício 2

Utilizando os recursos do banco de dados do GBIF e utilizando o pacote rgbif, apresente a localização de alguma espécie que você estude ou goste. Lembre-se que se a distribuição é muito ampla, os dados vão demorar a carregar, então limitar o número de observações ou escolher uma espécie de distribuição restrita pode ser uma opção!

library(rgbif)


ocorrencia<-occ_search(scientificName="Hyeronima alchorneoides", hasCoordinate=T, limit=500)

names(ocorrencia)
[1] "meta"      "hierarchy" "data"      "media"     "facets"   
localizacao <- as.data.frame(ocorrencia$data) %>% select(3:4) %>% 
  rename(Lat = decimalLatitude, Long=decimalLongitude)


ocorrencia.br<-occ_search(scientificName="Hyeronima alchorneoides", country="BR", hasCoordinate=T)

localizacao.br <- as.data.frame(ocorrencia.br$data) %>% rename(Lat = decimalLatitude, Long=decimalLongitude)


distribuicao<-c(min(localizacao$Long,na.rm=T)-1,
                min(localizacao$Lat,na.rm=T)-1,
                max(localizacao$Long,na.rm=T)+1,
                max(localizacao$Lat,na.rm=T)+1)

mundo <- map_data("world")

ggplot() + borders("world", colour="brown", fill="gray")+
  geom_sf(data=state_all, fill="lightgray", color="black")+
  coord_sf(xlim= c(-80,-35), ylim=c(-32,10))+
  theme_minimal() +
  geom_point(aes(Long,y=Lat), data=localizacao.br, color=localizacao.br$year, size=2.5,alpha=0.6)+
  theme(panel.grid.major = element_line(color = "gray", linetype = "dashed", size = 0.5), 
        panel.background = element_rect(fill = "lightblue"),
        axis.title = element_blank())+
  labs(title="Hyeronima alchorneoides")
Warning: Removed 1 rows containing missing values (`geom_point()`).

Exercício 3

Utilizando os dados de [Numbats na Australia](https://github.com/rfordatascience/tidytuesday/blob/master/data/2023/2023-03-07/readme.md), faça um mapa de ocorrência nos diferentes anos.(um mapa ou vários mapas)

numbats1 <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-03-07/numbats.csv')
Rows: 805 Columns: 16
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr  (6): scientificName, taxonConceptID, recordID, dataResourceName, month,...
dbl  (7): decimalLatitude, decimalLongitude, year, hour, prcp, tmax, tmin
lgl  (1): dryandra
dttm (1): eventDate
date (1): day

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
numbats <- numbats1 %>% rename(lat=decimalLatitude, long=decimalLongitude, yr=year) %>% subset(yr != "NA") %>%  select(-taxonConceptID, -recordID, -tmax, -tmin, -prcp) 


ggplot(mundo, aes(x=long, y=lat, group=group))+
  geom_polygon(fill="lightgray", colour = "black")

#ocorrencia geral
ggplot()+ borders("world", fill = "grey70", colour = "black", xlim= c(100,150), ylim=c(-50,0))+
  geom_point(aes(x=numbats$long, y=numbats$lat), color="red", alpha=0.5)+
  coord_fixed()
Warning: Removed 15 rows containing missing values (`geom_point()`).

#por especie
ggplot(data=numbats, aes(x=long, y=lat))+
  geom_map(data=mundo, map=mundo, aes(x=long, y=lat, map_id=region), fill="lightgray", color="black")+
  geom_point(aes(long, y=lat, color=yr), size= 3, alpha=0.5)+
  coord_fixed(xlim= c(100,150), ylim=c(-50,0))+
  facet_wrap(~scientificName)
Warning in geom_map(data = mundo, map = mundo, aes(x = long, y = lat, map_id = region), : Ignoring unknown aesthetics: x and y
Removed 15 rows containing missing values (`geom_point()`).

Exercício 4

Utilizando os dados de [Culturas agrícolas do passado](https://github.com/rfordatascience/tidytuesday/blob/master/data/2023/2023-04-18/readme.md) faça um mapa mostrando a ocorrência das diferentes famílias de culturas agrícolas. (um mapa ou vários mapas)

founder_crops <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-04-18/founder_crops.csv')
Rows: 4490 Columns: 24
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (18): source, source_id, source_site_name, site_name, phase, phase_descr...
dbl  (6): latitude, longitude, age_start, age_end, n, prop

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
crops<-founder_crops %>% select(-founder_crop, -edibility, -grass_type, - legume_type) %>% filter(category != "NA")

ggplot(data=crops, aes(x=longitude, y=latitude))+
  geom_map(data=mundo, map=mundo, aes(x=long, y=lat, map_id=region), fill="lightgray", color="black")+
  geom_point(aes(longitude, y=latitude, color=family), size= 2, alpha=0.5)+
  coord_fixed(xlim=c(20, 60), ylim=c(20, 50))
Warning in geom_map(data = mundo, map = mundo, aes(x = long, y = lat, map_id =
region), : Ignoring unknown aesthetics: x and y

ggplot(data=crops, aes(x=longitude, y=latitude))+
  geom_map(data=mundo, map=mundo, aes(x=long, y=lat, map_id=region), fill="lightgray", color="black")+
  geom_point(aes(longitude, y=latitude, color=family), size= 2, alpha=0.5)+
  coord_fixed(xlim=c(20, 60), ylim=c(20, 50))+
  facet_wrap(~category)+
  theme_classic()+
  theme(legend.background = element_blank(), legend.text=element_text(size=8),
        legend.title = element_blank(),
        legend.key.size = unit(0.8, "cm"),
        panel.grid.major = element_line(color = "gray", linetype = "dashed", size = 0.5), 
        panel.background = element_rect(fill = "lightblue"),
        axis.title = element_blank())
Warning in geom_map(data = mundo, map = mundo, aes(x = long, y = lat, map_id =
region), : Ignoring unknown aesthetics: x and y

O mapa ficou desconfigurado quando renderizei pelo quarto!

A imagem salva ficou melhor: