library(rnaturalearth)
library(sf)
library(terra)
library(dplyr)
library(ggmap)
library(ggplot2)
library(ggspatial)
library(geodata)
library(rgbif)
library(sp)
library(tmap)
library(ggrepel)Mapa
Carregar os pacotes
Carregar dados
neot<-st_read("dados/shapes/neotropica.shp")Reading layer `neotropica' from data source
`C:\Users\eliva\OneDrive\Área de Trabalho\Manipulação de dados\dados\shapes\neotropica.shp'
using driver `ESRI Shapefile'
Simple feature collection with 49 features and 11 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -151.4978 ymin: -58.49861 xmax: -26.24139 ymax: 32.71846
CRS: NA
paises<-ne_countries(scale="medium", returnclass = "sf")
bra<-ne_countries(country="Brazil")
st_crs(neot) = 4326
st_crs(bra) = 4326Filtrando apenas o Rio Grande do Sul
estados<-ne_states(country="Brazil")
estados<-st_make_valid(estados)
RS_mapa<-estados %>%
filter(name=="Rio Grande do Sul")
st_crs(RS_mapa) = 4326Carregar as coordenadas geográficas e ocorrencias
coord2<-read.csv("autocorrelação.csv", sep=";")
coord<-st_as_sf(coord2, coords = c("LONGITUDE_X", "LATITUDE_Y"))
st_crs(coord)<-4326
occs_bra<-st_intersection(coord, neot)
occs<-read.csv("dados/occs/cyclodium.csv")
occs<-st_as_sf(occs, coords = c("long", "lat"))
st_crs(occs)<-4326
occs_bra<-st_intersection(occs, bra)
st_crs(occs_bra)<-4326Gerando o Mapa Maior
mapa_local<-ggplot()+
geom_sf(data=neot, colour="darkgrey",fill="lightgrey", linetype="dashed")+
geom_sf(data=bra, fill="grey50")+
geom_sf(data=RS_mapa, fill="white")+
geom_text_repel(data=coord2, aes(x=LONGITUDE_X, y=LATITUDE_Y,
label= area))+
geom_sf(data=coord, aes(color=Type), pch=15, size=2)+
scale_color_manual(values="green2")+
coord_sf(xlim=c(-55,-49.5), ylim=c(-30,-25))+
theme_bw()+
labs(x=NULL, y=NULL)+
theme(panel.background = element_rect(fill="lightblue1"),
panel.grid=element_line(colour="grey80", linewidth = 0.2),
legend.key=element_rect(fill="white"),
legend.position = "none")+
annotation_north_arrow(style=north_arrow_orienteering,
location="br", height=unit(0.6, "cm"),
width = unit(0.6, "cm"))+
annotation_scale(location="tr", bar_cols= c("white", "black"),
line_width=0.5)
mapa_localCriamos uma legenda
Nossa legenda não estava funcionando, então criamos uma…
rect_df<- data.frame(xmin = c(0.6,1.6,2.6,3.2),
xmax = c(1.4,2.4,3.4, 4.3),
ymin = c(1,-1,-3, -1),
ymax = c(3,1,-1, 1),
grp = factor(c('Rio Grande do Sul','Brazil','South America', "Study areas"),
levels = c(c('Rio Grande do Sul','Brazil','South America', "Study areas"))))
legenda_g<-ggplot()+
geom_rect(data = rect_df,aes(x = NULL,y = NULL,xmin = xmin,
xmax = xmax,ymin = ymin,ymax = ymax,fill = grp))+
scale_fill_manual(values=c("white", "grey50", "lightgray", "green2"), name="Legend")+
theme(legend.title = element_text(size=6),
legend.text = element_text(size=5),
legend.key.size = unit(0.25,'cm'),
legend.box.background = element_rect(color="black"),
legend.background = element_blank())
legenda_gFazendo o mapa pequeno
mini_mapa<-ggplot()+
geom_sf(data=neot, colour="darkgrey",fill="lightgrey", linetype="dashed")+
geom_sf(data=bra, fill="grey50")+
geom_sf(data=RS_mapa, fill="white")+
theme_ps()+
theme(panel.border = element_rect(color="black", fill=NA),
panel.background = element_rect(fill="lightblue1"))+
coord_sf(xlim=c(-80,-35), ylim=c(-40,10))
mini_mapaGerando o mapa
library(cowplot)
legend <- cowplot::get_legend(legenda_g)
legendTableGrob (5 x 5) "guide-box": 2 grobs
z cells name grob
1 1 (3-3,3-3) guides gtable[layout]
2 0 (2-4,2-4) legend.box.background rect[GRID.rect.204]
legendmapa=ggdraw()+
draw_plot(mapa_local)+
draw_plot(mini_mapa, x=0.095, y=0.618, width = 0.35, height = 0.35)
mapa_2= legendmapa + annotation_custom(legend, xmin = 0.24, xmax = 0.25,
ymin = 0.12, ymax = 0.25)
mapa_2