Descarga de datos del GBIF

SIG
R
Descargando datos
Author

Daniela O

Published

September 17, 2024

Descargando datos

library(tidyverse)
library(rgbif)
# descargando datos

# Instalar y cargar la librería rgbif si no está instalada
if(!require(rgbif)) {
  install.packages("rgbif")
}
library(rgbif)

# Parámetros de búsqueda
taxon_key <- name_backbone(name="Mammalia")$usageKey # Buscar el código del taxón Mammalia
country_code <- "CO" # Código ISO para Colombia
department <- "Magdalena" # Departamento Magdalena

# Realizar la búsqueda de datos
occ_data <- occ_search(
  taxonKey = taxon_key, 
  country = country_code, 
  stateProvince = department, 
  hasCoordinate = TRUE,  # Filtrar solo registros con coordenadas
  limit = 1000 # Límite de registros
)

# Ver los primeros resultados
head(occ_data$data)
# A tibble: 6 × 147
  key        scientificName   decimalLatitude decimalLongitude issues datasetKey
  <chr>      <chr>                      <dbl>            <dbl> <chr>  <chr>     
1 4510334177 Dasyprocta punc…            11.1            -74.1 cdc,c… 50c9509d-…
2 4936855480 Saguinus oedipu…            11.3            -74.2 cdc,c… 50c9509d-…
3 4512238973 Cebus malitiosu…            11.2            -74.0 cdc,c… 50c9509d-…
4 4516701288 Alouatta senicu…            11.1            -74.1 cdc,c… 50c9509d-…
5 4516613051 Alouatta senicu…            11.3            -73.9 cdc,c… 50c9509d-…
6 4516840799 Cerdocyon thous…            11.3            -73.9 cdc    50c9509d-…
# ℹ 141 more variables: publishingOrgKey <chr>, installationKey <chr>,
#   hostingOrganizationKey <chr>, publishingCountry <chr>, protocol <chr>,
#   lastCrawled <chr>, lastParsed <chr>, crawlId <int>, basisOfRecord <chr>,
#   occurrenceStatus <chr>, lifeStage <chr>, taxonKey <int>, kingdomKey <int>,
#   phylumKey <int>, classKey <int>, orderKey <int>, familyKey <int>,
#   genusKey <int>, speciesKey <int>, acceptedTaxonKey <int>,
#   acceptedScientificName <chr>, kingdom <chr>, phylum <chr>, order <chr>, …
occ<- data.frame(occ_data$data)
# view(occ)

occ_depu<- occ |> select(-c(5,7,8,9,10,11,12,13,14,17,18,19,20,21,22,23,24,25,26,34,35,39,43:147))

glimpse(occ_depu)
Rows: 1,000
Columns: 20
$ key                    <chr> "4510334177", "4936855480", "4512238973", "4516…
$ scientificName         <chr> "Dasyprocta punctata Gray, 1842", "Saguinus oed…
$ decimalLatitude        <dbl> 11.14510, 11.25700, 11.23540, 11.09190, 11.2894…
$ decimalLongitude       <dbl> -74.11477, -74.16946, -73.95590, -74.07312, -73…
$ datasetKey             <chr> "50c9509d-22c7-4a22-a47d-8c48425ef4a7", "50c950…
$ basisOfRecord          <chr> "HUMAN_OBSERVATION", "HUMAN_OBSERVATION", "HUMA…
$ occurrenceStatus       <chr> "PRESENT", "PRESENT", "PRESENT", "PRESENT", "PR…
$ acceptedScientificName <chr> "Dasyprocta punctata Gray, 1842", "Saguinus oed…
$ kingdom                <chr> "Animalia", "Animalia", "Animalia", "Animalia",…
$ phylum                 <chr> "Chordata", "Chordata", "Chordata", "Chordata",…
$ order                  <chr> "Rodentia", "Primates", "Primates", "Primates",…
$ family                 <chr> "Dasyproctidae", "Callitrichidae", "Cebidae", "…
$ genus                  <chr> "Dasyprocta", "Saguinus", "Cebus", "Alouatta", …
$ species                <chr> "Dasyprocta punctata", "Saguinus oedipus", "Ceb…
$ taxonRank              <chr> "SPECIES", "SPECIES", "SPECIES", "SPECIES", "SP…
$ taxonomicStatus        <chr> "ACCEPTED", "ACCEPTED", "ACCEPTED", "ACCEPTED",…
$ iucnRedListCategory    <chr> "LC", "CR", "EN", "LC", "LC", "LC", "LC", "EN",…
$ continent              <chr> "SOUTH_AMERICA", "SOUTH_AMERICA", "SOUTH_AMERIC…
$ stateProvince          <chr> "Magdalena", "Magdalena", "Magdalena", "Magdale…
$ year                   <int> 2024, 2024, 2024, 2024, 2024, 2024, 2024, 2024,…
# write.csv2(occ_depu, "obs_mamigeros.csv")
# datos de herpetos 
if(!require(rgbif)) {
  install.packages("rgbif")
}
library(rgbif)

# Parámetros de búsqueda
taxon_key <- name_backbone(name="Reptilia")$usageKey # Buscar el código del taxón Mammalia
country_code <- "CO" # Código ISO para Colombia
department <- "Magdalena" # Departamento Magdalena

# Realizar la búsqueda de datos
occ_data <- occ_search(
  taxonKey = taxon_key, 
  country = country_code, 
  stateProvince = department, 
  hasCoordinate = TRUE,  # Filtrar solo registros con coordenadas
  limit = 2000 # Límite de registros
)

# Ver los primeros resultados
head(occ_data$data)
# A tibble: 6 × 101
  key        scientificName   decimalLatitude decimalLongitude issues datasetKey
  <chr>      <chr>                      <dbl>            <dbl> <chr>  <chr>     
1 4507796310 Anolis auratus …            11.2            -74.1 cdc,c… 50c9509d-…
2 4510128617 Tretioscincus b…            11.3            -74.0 cdc,c… 50c9509d-…
3 4510334177 Dasyprocta punc…            11.1            -74.1 cdc,c… 50c9509d-…
4 4510151452 Vanellus chilen…            11.2            -74.2 cdc,c… 50c9509d-…
5 4510413766 Atractus sancta…            11.1            -74.1 cdc,c… 50c9509d-…
6 4510187739 Mastigodryas bo…            11.1            -74.1 cdc,c… 50c9509d-…
# ℹ 95 more variables: publishingOrgKey <chr>, installationKey <chr>,
#   hostingOrganizationKey <chr>, publishingCountry <chr>, protocol <chr>,
#   lastCrawled <chr>, lastParsed <chr>, crawlId <int>, basisOfRecord <chr>,
#   occurrenceStatus <chr>, taxonKey <int>, kingdomKey <int>, phylumKey <int>,
#   classKey <int>, familyKey <int>, genusKey <int>, speciesKey <int>,
#   acceptedTaxonKey <int>, acceptedScientificName <chr>, kingdom <chr>,
#   phylum <chr>, family <chr>, genus <chr>, species <chr>, …
occ_reptilia<- data.frame(occ_data$data)
#view(occ_reptilia)

occ_depu_r<- occ_reptilia |> select(-c(7,8,9,10:13,14,17:24,36:58,60:101))

glimpse(occ_depu_r)
Rows: 2,000
Columns: 20
$ key                    <chr> "4507796310", "4510128617", "4510334177", "4510…
$ scientificName         <chr> "Anolis auratus Daudin, 1802", "Tretioscincus b…
$ decimalLatitude        <dbl> 11.23691, 11.32014, 11.14510, 11.22588, 11.1014…
$ decimalLongitude       <dbl> -74.14756, -73.95403, -74.11477, -74.18608, -74…
$ issues                 <chr> "cdc,cdround", "cdc,cdround", "cdc,cdround", "c…
$ datasetKey             <chr> "50c9509d-22c7-4a22-a47d-8c48425ef4a7", "50c950…
$ basisOfRecord          <chr> "HUMAN_OBSERVATION", "HUMAN_OBSERVATION", "HUMA…
$ occurrenceStatus       <chr> "PRESENT", "PRESENT", "PRESENT", "PRESENT", "PR…
$ acceptedScientificName <chr> "Anolis auratus Daudin, 1802", "Tretioscincus b…
$ kingdom                <chr> "Animalia", "Animalia", "Animalia", "Animalia",…
$ phylum                 <chr> "Chordata", "Chordata", "Chordata", "Chordata",…
$ family                 <chr> "Dactyloidae", "Gymnophthalmidae", "Dasyproctid…
$ genus                  <chr> "Anolis", "Tretioscincus", "Dasyprocta", "Vanel…
$ species                <chr> "Anolis auratus", "Tretioscincus bifasciatus", …
$ genericName            <chr> "Anolis", "Tretioscincus", "Dasyprocta", "Vanel…
$ specificEpithet        <chr> "auratus", "bifasciatus", "punctata", "chilensi…
$ taxonRank              <chr> "SPECIES", "SPECIES", "SPECIES", "SPECIES", "SP…
$ taxonomicStatus        <chr> "ACCEPTED", "ACCEPTED", "ACCEPTED", "ACCEPTED",…
$ iucnRedListCategory    <chr> "LC", "LC", "LC", "LC", "LC", NA, "LC", "LC", N…
$ class                  <chr> "Squamata", "Squamata", "Mammalia", "Aves", "Sq…
occ_depu_r$class <- as.factor(occ_depu_r$class)

# Ver los niveles de la variable categórica "class"
nombres_categorias <- levels(occ_depu_r$class)
print(nombres_categorias)
[1] "Amphibia"       "Aves"           "Crocodylia"     "Elasmobranchii"
[5] "Mammalia"       "Squamata"       "Testudines"    
occ_r <- occ_depu_r |> filter(class == c("Amphibia", "Mammalia" , "Squamata"))

# view(occ_r)

# write.csv2(occ_r, "obs_reptilia.csv")