#plot
library(ggplot2)
library(patchwork)
library(cowplot)
#map
library(rnaturalearth)
library(rmapshaper)
library(sf)
library(biscale)
08 - World map with countries represented by its NBT and native turnover for endemic species (Figure 3)
08_V_beta_endemics_Fig3.qmd
Plotting native and NBT turnover for endemic species for each country
Loading packages
Data used
# Data from 02_D_beta-countries.qmd
<- readr::read_csv(here::here("data", "processed", "df_endemic_beta.csv")) df_endemic_beta
Joining metric information with geographical data
<- rnaturalearth::ne_countries(returnclass = "sf")
countries
<-
sf_countries ::st_as_sf(countries) |>
sf::filter(admin != "Antarctica") |>
dplyr::st_transform(crs = "+proj=moll +x_0=0 +y_0=0 +lat_0=0 +lon_0=0") |>
sf::select(iso_a3_eh)
dplyr
<-
df_endemic_beta_sf |>
sf_countries ::full_join(df_endemic_beta, by = c(iso_a3_eh = "countries")) dplyr
First processing spatial data to convert NA values into 0
<-
df_endemic_beta_sf2 |>
df_endemic_beta_sf ::st_as_sf() |>
sf::ms_filter_islands(min_area = 12391399903) |>
rmapshaper::mutate(
dplyrtype.beta = ifelse(is.na(type.beta),
0,
type.beta),native.beta = ifelse(is.na(native.beta),
0,
native.beta))
Create palettes
<- colorRampPalette(c("#d3d3d3", "#accaca", "#81c1c1", "#52b6b6"))
palette_blue
<- colorRampPalette(c("#d3d3d3", "#c5acc2", "#bb84b1", "#ac5a9c")) palette_pink
Plotting maps
<-
map_native_endemic_beta ggplot() +
geom_sf(data = df_endemic_beta_sf2,
aes(geometry = geometry,
fill = native.beta),
color = "white",
size = 0.1, na.rm = T) +
scale_fill_gradientn(
colors = palette_pink(10),
na.value = "#d3d3d3",
limits = c(0,1)
+
)guides(fill = guide_colorbar(
barheight = unit(0.1, units = "in"),
barwidth = unit(4, units = "in"),
ticks.colour = "grey20",
title.position="top",
title.hjust = 0.5
+
)) labs(
fill = "Native"
+
)theme_classic()+
theme(
legend.position = "bottom",
legend.margin = margin(-10,0,0,0,"pt"),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.line = element_blank()
)
<-
map_type_endemic_beta ggplot() +
geom_sf(data = df_endemic_beta_sf2,
aes(geometry = geometry,
fill = type.beta),
color = "white",
size = 0.1, na.rm = T) +
scale_fill_gradientn(
colors = palette_blue(10),
na.value = "#d3d3d3",
limits = c(0,1)
+
)guides(fill = guide_colorbar(
barheight = unit(0.1, units = "in"),
barwidth = unit(4, units = "in"),
ticks.colour = "grey20",
title.position="top",
title.hjust = 0.5
+
)) labs(
fill = "Types"
+
)theme_classic()+
theme(
legend.position = "bottom",
legend.margin = margin(-10,0,0,0,"pt"),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.line = element_blank()
)
Plotting the two quantities (native and types turnover) in a bivariate map
<-
sf_bivar_types_endemic bi_class(df_endemic_beta_sf2,
x = type.beta,
y = native.beta,
style = "equal",
dim = 4)
<-
bivar_map_types_endemic ggplot() +
geom_sf(data = sf_bivar_types_endemic,
aes(geometry = geometry,
fill = bi_class),
color = "white",
size = 0.1,
show.legend = FALSE) +
bi_scale_fill(pal = "DkBlue2",
dim = 4) +
theme_classic()+
theme(
legend.position = "bottom",
legend.title = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.line = element_blank(),
panel.background = element_rect(fill = NA),
plot.background = element_rect(fill = NA)
)
<-
legend bi_legend(pal = "DkBlue2",
dim = 4,
xlab = "NBT",
ylab = "Native",
size = )
<-
bivar_map_type_final_endemic ggdraw() +
draw_plot(legend, 0.0, 0.15, 0.25, 0.25) +
draw_plot(bivar_map_types_endemic, 0, 0, 1, 1)
Joining all the maps
<-
map_turnover_endemic +map_type_endemic_beta+bivar_map_type_final_endemic+
map_native_endemic_beta::plot_layout(
patchworkdesign =
"AB
CC"
+
)::plot_annotation(tag_levels = "a")&
patchworktheme(
plot.tag = element_text(face = "bold", hjust = 0, vjust = 1),
plot.tag.position = c(0, 1),
)
map_turnover_endemic
ggsave(here::here("output", "figures", "Fig3_turnover_metrics_endemics.png"),
dpi=600, width = 10, height = 9) map_turnover_endemic,