Skip to content

2. Importing NDM VNDM outputs into R

Juan Pablo Narvaez-Gomez edited this page Oct 21, 2020 · 1 revision

Producing the Consensus Areas shapefiles

NDM/VNDM allows the user to save the grids forming the areas of endemism in formats amenable to GIS software. Among them, the grids and occurrence points can be saved as text files. Here the function ndm_gridtopoly() was designed to transform this text files into polygons. These files were saved using the nomenclature described above.


# 1. Creating polygons from NDM grid output file at each spatial scale ####

# 1.1. File lists of consensus areas names ####

ndm_listgrid.files(path = "./data/GIS/40perc/", degree = 1)
ndm_listgrid.files(path = "./data/GIS/40perc/", degree = 2)
ndm_listgrid.files(path = "./data/GIS/40perc/", degree = 3)

# 1.2 Creating polygons from grid files ####

## Consensus areas shapefiles are saved in"./output/GIS/40perc/".
## A copy of the output of ndm_gridtopoly() can be found in 
## "./data/GIS/Consensus_Areas_Shapefiles/".

pmap(list(file = files1dg,
          degree = 1,
          save.area.shp = TRUE,
          save.directory = "./output/GIS/40perc/",
          area.shp.name = anames1dg), ndm_gridtopoly)

pmap(list(file = files2dg,
          degree = 2,
          save.area.shp = TRUE,
          save.directory = "./output/GIS/40perc/",
          area.shp.name = anames2dg), ndm_gridtopoly)

pmap(list(file = files3dg,
          degree = 3,
          save.area.shp = TRUE,
          save.directory = "./output/GIS/40perc/",
          area.shp.name = anames3dg), ndm_gridtopoly)

Importing the VNDM-NDM text file output

The output file with the complete information about the endemicity analysis can be imported into R using the function ndm_dataparsing(). When this function was developed, I did not find an automatic way to easily extract the range of values of the index of endemicity (IE) for each consensus area. This information was introduced manually in the output of ndm_dataparsing(). The resulting data frame was saved in: ./data/ndm_outputs/CA_Loose40_dataDS.xlsx

# 2. Consensus areas data frames and NDM data matrices from NDM output file ####

# 2.1. Default ####

# ndm_dataparsing function: Parsing the output text file into R
# ndmfile = c("./1dgD_total.out", "./2dgD_total.out", "./3dgD_total.out")
# grid_size = c(1, 2, 3)
e_ndm <- raster::extent(c(-111, -31, -40, 40))

df_2D <- ndm_dataparsing(ndmfile = "./data/ndm-outputs/Loose40/2dgD_total.out", 
                         grid_size = 2, ana_param = "D", 
                         create_matrix = TRUE, matrix_extent = e_ndm) 

# Visualization of matrices at 2 degrees

# Visualization for Default analysis is provided. To visualize the Strict
# analysis change the parameter 'ana_param' from "D" to "S" in the function 
# ndm_datamatrix_plot().

ndm_datamatrix_plot(cm_shpfile = "./data/GIS/Amer_land.shp", 
                    ndm_raster = Records_cell, ndm_title = "Sampling", 
                    legend_title = "Records")
ndm_datamatrix_plot(cm_shpfile = "./data/GIS/Amer_land.shp", 
                    ndm_raster = Species_cell, ndm_title = "Richness", 
                    legend_title = "Species")
ndm_datamatrix_plot(cm_shpfile = "./data/GIS/Amer_land.shp", 
                    ndm_raster = Assumed_cell, ndm_title = "Filling effect", 
                    legend_title = "Assumed\nspecies")

# 2.3. Strict ####

# The same as the Default analysis.
df_2S <- ndm_dataparsing(ndmfile = "./data/ndm-outputs/Loose40/2dgS_total.out",
                         grid_size = 2, ana_param = "S", create_matrix = TRUE, 
                         matrix_extent = e_ndm)