The purpose of this post is to download data from GBIF to obtain occurrences registries of a particular species and then to transform that data into a geospatial object and obtain a map.
The first step is to load the required packages. Rgbif is the package that will connect R with the GBIF API, skimr is going to be useful to get a quick view of the data we just downloaded, dply and tidyr will help wrangle and clean the data, rnaturalearth will be used to download a polygon of Mexico’s extent, while sf is going to be used to transform the data into a spatial object (sf) and finally, tmap will be used to make a map.
The first step will be to set your credentials to be able to acess GBIF. If you do not have these credentials, you can register in their website and obtain them (https://www.gbif.org/user/profile). Then rewrite that information into the R environment
The next step is downloading the data of interest. In this example, I am going to download the data for Rhizhophora mangle in Mexico. You will have to wait for the download to complete. Meanwhile, you can check the status of the download using occ_download_wait and putting in the key of numbers that will appear in the console. Once the download have been finished, you can import the data into R.
Next, you can use skimr to take a look at the general structure of the data and select the columns of interest. Additinoally, you can drop registries without location. (longitude / latitude).
Finally, you can transform the data into a spatial object and make a map. Here, I use ne_countries to get the polygon of Mexico and tmap to create the map. Finally, you can export the map.