Skip to contents

A wrapper of [rgbif::occ_search()] function to get the number of occurences. Optionally, the number of occurrences can be obtained by years or by country.

Usage

tax_gbif_occur_pq(
  physeq = NULL,
  taxnames = NULL,
  taxonomic_rank = "currentCanonicalSimple",
  add_to_phyloseq = NULL,
  col_prefix = NULL,
  by_country = FALSE,
  by_years = FALSE,
  verbose = TRUE,
  time_to_sleep = 0.3,
  discard_genus_alone = taxonomic_rank == "currentCanonicalSimple",
  discard_NA = TRUE
)

Arguments

physeq

(optional) A phyloseq object. Either `physeq` or `taxnames` must be provided, but not both.

taxnames

(optional) A character vector of taxonomic names.

taxonomic_rank

(Character, default "currentCanonicalSimple") The column(s) present in the @tax_table slot of the phyloseq object. Can be a vector of two columns (e.g. c("Genus", "Species")).

add_to_phyloseq

(logical, default TRUE when physeq is provided, FALSE when taxnames is provided) If TRUE, add new column(s) in the tax_table of the phyloseq object. Automatically set to TRUE when a phyloseq object is provided and FALSE when taxnames is provided. Cannot be TRUE if `taxnames` is provided.

col_prefix

A character string to be added as a prefix to the new columns names added to the tax_table slot of the phyloseq object (default: NULL).

by_country

(logical, default FALSE) If TRUE, the number of occurences is computed by country

by_years

(logical, default FALSE) If TRUE, the number of occurences is computed by years

verbose

(logical, default TRUE) If TRUE, prompt some messages.

time_to_sleep

(numeric, default 0.3) Time to sleep between two calls to rgbif::occ_search(). Useful to avoid to be blocked by GBIF. Try to increase this value if you are blocked by the error "To download GBIF occurrence data in bulk, please request..."

Value

Either a tibble (if add_to_phyloseq = FALSE) or a new phyloseq object, if add_to_phyloseq = TRUE, with new column(s) in the tax_table.

Details

This function is mainly a wrapper of the work of others. Please cite `rgbif` package.

See also

[rgbif::occ_search()], [plot_tax_gbif_pq()], [tax_occurr_pq()]

Author

Adrien Taudiere

Examples

data_fungi_mini_cleanNames <-
  gna_verifier_pq(data_fungi_mini)
#>  GNA verification summary:
#>  Total taxa in phyloseq: 45
#>  Taxa submitted for verification: 37
#>  Genus-level only taxa: 2
#>  Total matches found: 25
#>  Synonyms: 2 (including 2 at genus level)
#>  Accepted names: 23 (including 21 at genus level)

# \donttest{
data_fungi_mini_cleanNames <- tax_gbif_occur_pq(data_fungi_mini_cleanNames, by_country = TRUE)
#> ■■                                 4% | ETA:  7s
#>  Processing GBIF occurrences for Stereum ostrea
#> ■■                                 4% | ETA:  7s

#> ■■■■                               9% | ETA:  8s
#>  Processing GBIF occurrences for Xylodon raduloides
#> ■■■■                               9% | ETA:  8s

#>  Processing GBIF occurrences for Stereum hirsutum
#> ■■■■                               9% | ETA:  8s

#>  Processing GBIF occurrences for Trametopsis brasiliensis
#> ■■■■                               9% | ETA:  8s

#>  Processing GBIF occurrences for Basidiodendron eyrei
#> ■■■■                               9% | ETA:  8s

#>  Processing GBIF occurrences for Sistotrema oblongisporum
#> ■■■■                               9% | ETA:  8s

#>  Processing GBIF occurrences for Fomes fomentarius
#> ■■■■                               9% | ETA:  8s

#>  Processing GBIF occurrences for Mycena renati
#> ■■■■                               9% | ETA:  8s

#> ■■■■■■■■■■■■■                     39% | ETA:  6s
#>  Processing GBIF occurrences for Helicogloea pellucida
#> ■■■■■■■■■■■■■                     39% | ETA:  6s

#>  Processing GBIF occurrences for Radulomyces molaris
#> ■■■■■■■■■■■■■                     39% | ETA:  6s

#>  Processing GBIF occurrences for Elmerina caryae
#> ■■■■■■■■■■■■■                     39% | ETA:  6s

#>  Processing GBIF occurrences for Phanerochaete livescens
#> ■■■■■■■■■■■■■                     39% | ETA:  6s

#>  Processing GBIF occurrences for Gloeohypochnicium analogum
#> ■■■■■■■■■■■■■                     39% | ETA:  6s

#>  Processing GBIF occurrences for Hyphoderma roseocremeum
#> ■■■■■■■■■■■■■                     39% | ETA:  6s

#> ■■■■■■■■■■■■■■■■■■■■■             65% | ETA:  4s
#>  Processing GBIF occurrences for Hyphoderma setigerum
#> ■■■■■■■■■■■■■■■■■■■■■             65% | ETA:  4s

#>  Processing GBIF occurrences for Trametes versicolor
#> ■■■■■■■■■■■■■■■■■■■■■             65% | ETA:  4s

#>  Processing GBIF occurrences for Peniophora versiformis
#> ■■■■■■■■■■■■■■■■■■■■■             65% | ETA:  4s

#>  Processing GBIF occurrences for Exidia glandulosa
#> ■■■■■■■■■■■■■■■■■■■■■             65% | ETA:  4s

#>  Processing GBIF occurrences for Peniophorella pubera
#> ■■■■■■■■■■■■■■■■■■■■■             65% | ETA:  4s

#>  Processing GBIF occurrences for Auricularia mesenterica
#> ■■■■■■■■■■■■■■■■■■■■■             65% | ETA:  4s

#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■■      91% | ETA:  1s
#>  Processing GBIF occurrences for Laetisaria buckii
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■■      91% | ETA:  1s

#>  Processing GBIF occurrences for Hericium coralloides
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■■      91% | ETA:  1s

#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■  100% | ETA:  0s
#> 
#>  Processing GBIF occurrences for Xylodon flaviporus

# Get data without adding to phyloseq
tax_gbif_occur_pq(data_fungi_mini_cleanNames, add_to_phyloseq = FALSE)
#>  Processing GBIF occurrences for Stereum ostrea
#> ■■■■                               9% | ETA:  7s
#>  Processing GBIF occurrences for Xylodon raduloides
#> ■■■■                               9% | ETA:  7s

#>  Processing GBIF occurrences for Stereum hirsutum
#> ■■■■                               9% | ETA:  7s

#>  Processing GBIF occurrences for Trametopsis brasiliensis
#> ■■■■                               9% | ETA:  7s

#>  Processing GBIF occurrences for Basidiodendron eyrei
#> ■■■■                               9% | ETA:  7s

#>  Processing GBIF occurrences for Sistotrema oblongisporum
#> ■■■■                               9% | ETA:  7s

#>  Processing GBIF occurrences for Fomes fomentarius
#> ■■■■                               9% | ETA:  7s

#>  Processing GBIF occurrences for Mycena renati
#> ■■■■                               9% | ETA:  7s

#> ■■■■■■■■■■■■■                     39% | ETA:  6s
#>  Processing GBIF occurrences for Helicogloea pellucida
#> ■■■■■■■■■■■■■                     39% | ETA:  6s

#>  Processing GBIF occurrences for Radulomyces molaris
#> ■■■■■■■■■■■■■                     39% | ETA:  6s

#>  Processing GBIF occurrences for Elmerina caryae
#> ■■■■■■■■■■■■■                     39% | ETA:  6s

#>  Processing GBIF occurrences for Phanerochaete livescens
#> ■■■■■■■■■■■■■                     39% | ETA:  6s

#>  Processing GBIF occurrences for Gloeohypochnicium analogum
#> ■■■■■■■■■■■■■                     39% | ETA:  6s

#>  Processing GBIF occurrences for Hyphoderma roseocremeum
#> ■■■■■■■■■■■■■                     39% | ETA:  6s

#> ■■■■■■■■■■■■■■■■■■■■■             65% | ETA:  4s
#>  Processing GBIF occurrences for Hyphoderma setigerum
#> ■■■■■■■■■■■■■■■■■■■■■             65% | ETA:  4s

#>  Processing GBIF occurrences for Trametes versicolor
#> ■■■■■■■■■■■■■■■■■■■■■             65% | ETA:  4s

#>  Processing GBIF occurrences for Peniophora versiformis
#> ■■■■■■■■■■■■■■■■■■■■■             65% | ETA:  4s

#>  Processing GBIF occurrences for Exidia glandulosa
#> ■■■■■■■■■■■■■■■■■■■■■             65% | ETA:  4s

#>  Processing GBIF occurrences for Peniophorella pubera
#> ■■■■■■■■■■■■■■■■■■■■■             65% | ETA:  4s

#>  Processing GBIF occurrences for Auricularia mesenterica
#> ■■■■■■■■■■■■■■■■■■■■■             65% | ETA:  4s

#>  Processing GBIF occurrences for Laetisaria buckii
#> ■■■■■■■■■■■■■■■■■■■■■             65% | ETA:  4s

#>  Processing GBIF occurrences for Hericium coralloides
#> ■■■■■■■■■■■■■■■■■■■■■             65% | ETA:  4s

#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■  100% | ETA:  0s
#> 
#>  Processing GBIF occurrences for Xylodon flaviporus
#> # A tibble: 23 × 2
#>    Global_occurences canonicalName           
#>                <int> <chr>                   
#>  1             10908 Stereum ostrea          
#>  2              5676 Xylodon raduloides      
#>  3            121604 Stereum hirsutum        
#>  4                 8 Trametopsis brasiliensis
#>  5              1156 Basidiodendron eyrei    
#>  6              3032 Sistotrema oblongisporum
#>  7            168532 Fomes fomentarius       
#>  8              5676 Mycena renati           
#>  9                42 Helicogloea pellucida   
#> 10              4682 Radulomyces molaris     
#> # ℹ 13 more rows
tax_gbif_occur_pq(data_fungi_mini_cleanNames, by_years = TRUE, add_to_phyloseq = FALSE)
#>  Processing GBIF occurrences for Stereum ostrea
#>  Processing GBIF occurrences for Xylodon raduloides
#>  Processing GBIF occurrences for Stereum hirsutum
#>  Processing GBIF occurrences for Trametopsis brasiliensis
#> ■■■■■■■■                          22% | ETA:  8s
#>  Processing GBIF occurrences for Basidiodendron eyrei
#> ■■■■■■■■                          22% | ETA:  8s

#>  Processing GBIF occurrences for Sistotrema oblongisporum
#> ■■■■■■■■                          22% | ETA:  8s

#>  Processing GBIF occurrences for Fomes fomentarius
#> ■■■■■■■■                          22% | ETA:  8s

#>  Processing GBIF occurrences for Mycena renati
#> ■■■■■■■■                          22% | ETA:  8s

#>  Processing GBIF occurrences for Helicogloea pellucida
#> ■■■■■■■■                          22% | ETA:  8s

#> ■■■■■■■■■■■■■■                    43% | ETA:  7s
#>  Processing GBIF occurrences for Radulomyces molaris
#> ■■■■■■■■■■■■■■                    43% | ETA:  7s

#>  Processing GBIF occurrences for Elmerina caryae
#> ■■■■■■■■■■■■■■                    43% | ETA:  7s

#>  Processing GBIF occurrences for Phanerochaete livescens
#> ■■■■■■■■■■■■■■                    43% | ETA:  7s

#>  Processing GBIF occurrences for Gloeohypochnicium analogum
#> ■■■■■■■■■■■■■■                    43% | ETA:  7s

#>  Processing GBIF occurrences for Hyphoderma roseocremeum
#> ■■■■■■■■■■■■■■                    43% | ETA:  7s

#>  Processing GBIF occurrences for Hyphoderma setigerum
#> ■■■■■■■■■■■■■■                    43% | ETA:  7s

#> ■■■■■■■■■■■■■■■■■■■■■■            70% | ETA:  4s
#>  Processing GBIF occurrences for Trametes versicolor
#> ■■■■■■■■■■■■■■■■■■■■■■            70% | ETA:  4s

#>  Processing GBIF occurrences for Peniophora versiformis
#> ■■■■■■■■■■■■■■■■■■■■■■            70% | ETA:  4s

#>  Processing GBIF occurrences for Exidia glandulosa
#> ■■■■■■■■■■■■■■■■■■■■■■            70% | ETA:  4s

#>  Processing GBIF occurrences for Peniophorella pubera
#> ■■■■■■■■■■■■■■■■■■■■■■            70% | ETA:  4s

#>  Processing GBIF occurrences for Auricularia mesenterica
#> ■■■■■■■■■■■■■■■■■■■■■■            70% | ETA:  4s

#>  Processing GBIF occurrences for Laetisaria buckii
#> ■■■■■■■■■■■■■■■■■■■■■■            70% | ETA:  4s

#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■    96% | ETA:  1s
#>  Processing GBIF occurrences for Hericium coralloides
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■    96% | ETA:  1s

#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■  100% | ETA:  0s
#> 
#>  Processing GBIF occurrences for Xylodon flaviporus
#> # A tibble: 23 × 57
#> # Groups:   canonicalName [23]
#>    canonicalName  `2024` `2025` `2023` `2022` `2021` `2012` `2013` `2005` `2018`
#>    <chr>           <int>  <int>  <int>  <int>  <int>  <int>  <int>  <int>  <int>
#>  1 Stereum ostrea    905    837    705    316    208    176    154    132    121
#>  2 Xylodon radul…     NA     NA     NA     NA     NA    156     NA    149    179
#>  3 Stereum hirsu…   6210   6380   7024   5212   5054   3129     NA     NA   3025
#>  4 Trametopsis b…     NA     NA     NA     NA     NA     NA     NA     NA     NA
#>  5 Basidiodendro…     NA     NA     NA     NA     NA     NA     29     NA     41
#>  6 Sistotrema ob…     NA     NA     NA     NA    151     83    301     NA     74
#>  7 Fomes fomenta…  19251  22757  18655  17498  13162     NA     NA     NA   4446
#>  8 Mycena renati     449    424    386    307    274     NA     NA     NA    231
#>  9 Helicogloea p…     NA     NA      2     NA     NA     NA     NA     NA      1
#> 10 Radulomyces m…     NA    135    139     NA     NA     NA     NA     NA    144
#> # ℹ 13 more rows
#> # ℹ 47 more variables: `2001` <int>, `2019` <int>, `2006` <int>, `2007` <int>,
#> #   `2016` <int>, `2017` <int>, `2020` <int>, `2000` <int>, `1992` <int>,
#> #   `1999` <int>, `1979` <int>, `1990` <int>, `1997` <int>, `1939` <int>,
#> #   `1936` <int>, `1998` <int>, `1956` <int>, `2014` <int>, `2015` <int>,
#> #   `2009` <int>, `1941` <int>, `2010` <int>, `2008` <int>, `2002` <int>,
#> #   `2004` <int>, `1901` <int>, `2011` <int>, `1975` <int>, `1996` <int>, …

# Using taxnames vector (returns a tibble)
tax_gbif_occur_pq(taxnames = c("Amanita muscaria", "Boletus edulis"))
#>  Processing GBIF occurrences for Amanita muscaria
#>  Processing GBIF occurrences for Boletus edulis
#> # A tibble: 2 × 2
#>   Global_occurences canonicalName   
#>               <int> <chr>           
#> 1            311346 Amanita muscaria
#> 2             78157 Boletus edulis  
ggplot(
  data_fungi_mini_cleanNames@tax_table,
  aes(y = log10(as.numeric(Global_occurences)), x = currentCanonicalSimple)
) +
  geom_col() +
  geom_col(aes(y = -log10(as.numeric(FR))), fill = "blue") +
  coord_flip() +
  xlab("Number of occurences (log10 scale) at global (grey) scale and in France (blue)")
#> Error in geom_col(): Problem while computing aesthetics.
#>  Error occurred in the 1st layer.
#> Caused by error:
#> ! object 'Global_occurences' not found
# }