Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
added more examples to rgbif post
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Oct 9, 2012
1 parent a9088fd commit 36fcd7c
Show file tree
Hide file tree
Showing 92 changed files with 8,965 additions and 437 deletions.
30 changes: 26 additions & 4 deletions _drafts/2012-10-08-rgbif-newfxns.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tags:
- macroecology
---

[UPDATE]: In response to Jarrett's query I laid out a separate use case in which you may want to query by higher taxonomic rankings than species. See below
#### UPDATE: In response to Jarrett's query I laid out a separate use case in which you may want to query by higher taxonomic rankings than species. See below. In addition, added examples of querying by location in reply to comments by seminym.

*****

Expand Down Expand Up @@ -71,15 +71,37 @@ gbifmap(out)
out2 <- densitylist(originisocountrycode = "CA") # data for Canada
gbifmap(out2) # on world map
gbifmap(out2, "Canada") # on Canada map
````
```

*****

### We can also query by higher taxonomic rankings, and map all lower species within that ranking. Above we queried by scientificname, but we can also query by higher taxonomy. 7071443 is the taxonconceptkey for 'Bacillariophyceae', a Class which includes many lower species.
```{r fig.width=8, fig.height=5, gbifmap4 }
```{r fig.width=8, fig.height=5, algae }
out <- densitylist(taxonconceptKey=7071443)
gbifmap(out)
````
```

### seminym asked about querying by area. You can query by area, though slightly differently for occurrencelist and densitylist functions. For occurrencelist you can search using min and max lat and long values (and min an max altitude, pretty cool, eh).
```{r fig.width=8, fig.height=5, byarea_occurr }
# Get occurrences or density by area, using min/max lat/long coordinates
out <- occurrencelist(minlatitude=30, maxlatitude=35, minlongitude=-100, maxlongitude=-95,
coordinatestatus = T, maxresults = 5000, latlongdf = T)
# Using `geom_point`
gbifmap(out, "state", "texas", geom_point)
# Using geom_jitter to move the points apart from one another
gbifmap(out, "state", "texas", geom_jitter, position_jitter(width = 0.3, height = 0.3))
# And move points a lot
gbifmap(out, "state", "texas", geom_jitter, position_jitter(width = 1, height = 1))
```

### And you can query by area in `densitylist` by specifying a place using the `originisocountrycode` argument (as done in an above example). Just showing the head of the data.frame here.
```{r fig.width=8, fig.height=5, byarea_density }
# Get density by place, note that you can't use the lat and long arguments in densitylist
head( densitylist(originisocountrycode="CA") )
```

*********
#### Get the .Rmd file used to create this post [at my github account](https://github.com/SChamberlain/schamberlain.github.com/blob/master/_drafts/2012-10-08-rgbif-newfxns.Rmd) - or [.md file](https://github.com/SChamberlain/schamberlain.github.com/tree/master/_posts/2012-10-08-rgbif-newfxns.md).
Expand Down
112 changes: 90 additions & 22 deletions _posts/2012-10-08-rgbif-newfxns.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tags:
- macroecology
---

UPDATE: In response to Jarrett's query I laid out a separate use case in which you may want to query by higher taxonomic rankings than species. See below
#### UPDATE: In response to Jarrett's query I laid out a separate use case in which you may want to query by higher taxonomic rankings than species. See below. In addition, added examples of querying by location in reply to comments by seminym.

*****

Expand Down Expand Up @@ -98,39 +98,46 @@ density_spplist(originisocountrycode = "CO", spplist = "random")[1:10]


{% highlight text %}
[1] "Argyropelecus" "Argyropelecus lychnus lychnus"
[3] "Cheilopogon nigricans" "Cyclothone"
[5] "Globigerina bulloides" "Globigerina quinqueloba"
[7] "Globigerina rubescens" "Globigerinella aequilateralis"
[9] "Globigerinita glutinata" "Globigerinoides conglobatus"
[1] "Actinote cf. guatemalena" "Actinote desmiala"
[3] "Actinote guatemalena" "Allogamus chrysus"
[5] "Amaranthaceae" "Amphoropsyche cassius"
[7] "Anabolia incertina" "Aneuraceae"
[9] "Annonaceae Juss." "Anopheles argyritarsis"
{% endhighlight %}



{% highlight r %}
# density_spplist(originisocountrycode = 'CO', spplist = 'r') # can abbreviate the `spplist`
# argument
# density_spplist(originisocountrycode = 'CO', spplist = 'r') # can
# abbreviate the `spplist` argument

# Get a species list by cell, choosing the one with the greatest no. of records
# Get a species list by cell, choosing the one with the greatest no. of
# records
density_spplist(originisocountrycode = "CO", spplist = "great")[1:10] # great is abbreviated from `greatest`
{% endhighlight %}



{% highlight text %}
[1] "Acanthaceae Juss." "Accipitridae sp."
[3] "Accipitriformes/Falconiformes sp." "Apodidae sp."
[5] "Apodidae sp. (large swift sp.)" "Apodidae sp. (small swift sp.)"
[7] "Arctiinae" "Asteraceae Bercht. & J. Presl"
[9] "Asteraceae sp. 1" "Asteraceae sp. 6"
[1] "Acanthaceae Juss."
[2] "Accipitridae sp."
[3] "Accipitriformes/Falconiformes sp."
[4] "Apodidae sp."
[5] "Apodidae sp. (large swift sp.)"
[6] "Apodidae sp. (small swift sp.)"
[7] "Arctiinae"
[8] "Asteraceae Bercht. & J. Presl"
[9] "Asteraceae sp. 1"
[10] "Asteraceae sp. 6"
{% endhighlight %}



{% highlight r %}

# Can also get a data.frame with counts instead of the species list
density_spplist(originisocountrycode = "CO", spplist = "great", listcount = "counts")[1:10, ]
density_spplist(originisocountrycode = "CO", spplist = "great", listcount = "counts")[1:10,
]
{% endhighlight %}


Expand All @@ -153,7 +160,8 @@ density_spplist(originisocountrycode = "CO", spplist = "great", listcount = "cou
### You can now map point results, from fxns `occurrencelist` and those from `densitylist`, which plots them as points or as tiles, respectively. Point map, using output from occurrencelist.

{% highlight r %}
out <- occurrencelist(scientificname = "Puma concolor", coordinatestatus = TRUE, maxresults = 100, latlongdf = T)
out <- occurrencelist(scientificname = "Puma concolor", coordinatestatus = TRUE,
maxresults = 100, latlongdf = T)
gbifmap(input = out) # make a map, plotting on world map
{% endhighlight %}

Expand All @@ -164,11 +172,16 @@ gbifmap(input = out) # make a map, plotting on world map

{% highlight r %}
splist <- c("Accipiter erythronemius", "Junco hyemalis", "Aix sponsa", "Buteo regalis")
out <- lapply(splist, function(x) occurrencelist(x, coordinatestatus = T, maxresults = 100, latlongdf = T))
out <- lapply(splist, function(x) occurrencelist(x, coordinatestatus = T, maxresults = 100,
latlongdf = T))
gbifmap(out)
{% endhighlight %}

![center](/img/gbifmap2.png)


{% highlight text %}
Error: could not find function "capwords"
{% endhighlight %}


### Tile map, using output from densitylist, using results in Canada only.
Expand All @@ -178,25 +191,80 @@ out2 <- densitylist(originisocountrycode = "CA") # data for Canada
gbifmap(out2) # on world map
{% endhighlight %}

![center](/img/gbifmap31.png)
![center](/img/gbifmap3.png)

{% highlight r %}
gbifmap(out2, "Canada") # on Canada map
{% endhighlight %}

![NA](/img/gbifmap32.png)


{% highlight text %}
Error: object 'CanadaMapEnv' not found
{% endhighlight %}


*****

### We can also query by higher taxonomic rankings, and map all lower species within that ranking. Above we queried by scientificname, but we can also query by higher taxonomy. 7071443 is the taxonconceptkey for 'Bacillariophyceae', a Class which includes many lower species. Check out the page for 'Bacillariophyceae' [here](http://data.gbif.org/species/7071443).
### We can also query by higher taxonomic rankings, and map all lower species within that ranking. Above we queried by scientificname, but we can also query by higher taxonomy. 7071443 is the taxonconceptkey for 'Bacillariophyceae', a Class which includes many lower species.

{% highlight r %}
out <- densitylist(taxonconceptKey = 7071443)
gbifmap(out)
{% endhighlight %}

![center](/img/gbifmap4.png)
![center](/img/algae.png)


### seminym asked about querying by area. You can query by area, though slightly differently for occurrencelist and densitylist functions. For occurrencelist you can search using min and max lat and long values (and min an max altitude, pretty cool, eh).

{% highlight r %}
# Get occurrences or density by area, using min/max lat/long coordinates
out <- occurrencelist(minlatitude = 30, maxlatitude = 35, minlongitude = -100,
maxlongitude = -95, coordinatestatus = T, maxresults = 5000, latlongdf = T)

# Using `geom_point`
gbifmap(out, "state", "texas", geom_point)
{% endhighlight %}

![center](/img/byarea_occurr1.png)

{% highlight r %}

# Using geom_jitter to move the points apart from one another
gbifmap(out, "state", "texas", geom_jitter, position_jitter(width = 0.3, height = 0.3))
{% endhighlight %}

![NA](/img/byarea_occurr2.png)

{% highlight r %}

# And move points a lot
gbifmap(out, "state", "texas", geom_jitter, position_jitter(width = 1, height = 1))
{% endhighlight %}

![NA](/img/byarea_occurr3.png)


### And you can query by area in `densitylist` by specifying a place using the `originisocountrycode` argument (as done in an above example). Just showing the head of the data.frame here.

{% highlight r %}
# Get density by place, note that you can't use the lat and long arguments
# in densitylist
head(densitylist(originisocountrycode = "CA"))
{% endhighlight %}



{% highlight text %}
cellid minLatitude maxLatitude minLongitude maxLongitude count
1 46913 40 41 -67 -66 44
2 46914 40 41 -66 -65 907
3 46915 40 41 -65 -64 510
4 46916 40 41 -64 -63 645
5 46917 40 41 -63 -62 56
6 46918 40 41 -62 -61 143
{% endhighlight %}


*********
Expand Down
Loading

0 comments on commit 36fcd7c

Please sign in to comment.