GBIF biodiversity data from R - more functions

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. We have been working on an R package to get GBIF data from R, with the stable version available through CRAN, and the development version available on GitHub at https://github.com/rgbif ...

October 8, 2012 · 5 min · Scott Chamberlain

Vertnet - getting vertebrate museum record data and a quick map

We (rOpenSci) started a repo to wrap the API for VertNet, an open access online database of vertebrate specimen records across many collection holders. Find the open source code here - please contribute if you are so inclined. We had a great Google Summer of Code student, Vijay Barve contributing to the repo this summer, so it is getting close to being CRAN-able. Most of the functions in the repo get you the raw data, but there were no functions to visualize the data. Since much of the data records of latitude and longitude data, maps are a natural visualization to use. ...

September 19, 2012 · 2 min · Scott Chamberlain

Getting data from figures in published papers

The problem: There are a lot of figures in published papers in the scholarly literature, like the below, from (Attwood et. al. 2012)): At some point, a scientist wants to ask a question for which they can synthesize the knowledge on that question by collecting data from the published literature. This often requires something like the following workflow: Search for relevant papers (e.g., via Google Scholar). Collect the papers. Decide which are appropriate for inclusion. Collect data from the figures using software on a native application. Examples include GraphClick and ImageJ. Proof data. Analyze data & publish paper. This workflow needs revamping, particularly in step number 3 - collecting the data. This data remains private, moving from one closed source (original publication) to another (personal computer). We can surely do better. ...

September 18, 2012 · 5 min · Scott Chamberlain

Scholarly metadata from R

Metadata! Metadata is very cool. It’s super hot right now - everybody is talking about it. Okay, maybe not everyone, but it’s an important part of archiving scholarly work. We are working on a repo on GitHub rmetadata to be a one stop shop for querying metadata from around the web. Various repos on GitHub we have started - rpmc, rdatacite, rdryad, rpensoft, rhindawi - will at least in part be folded into rmetadata. As a start we are writing functions to hit any metadata services that use the OAI-PMH: “Open Archives Initiative Protocol for Metadata Harvesting” framework. OAI-PMH has six methods (or verbs as they are called) for data harvesting that are the same across different metadata providers: ...

September 17, 2012 · 6 min · Scott Chamberlain

Getting data on your government

I created an R package a while back to interact with some APIs that serve up data on what our elected represenatives are up to, including the New York Times Congress API, and the Sunlight Labs API. What kinds of things can you do with govdat? Here are a few examples. How do the two major parties differ in the use of certain words (searches the congressional record using the Sunlight Labs Capitol Words API)? ...

September 1, 2012 · 3 min · Scott Chamberlain

Getting ecology and evolution journal titles from R

So I want to mine some #altmetrics data for some research I’m thinking about doing. The steps would be: Get journal titles for ecology and evolution journals. Get DOI’s for all papers in all the above journal titles. Get altmetrics data on each DOI. Do some fancy analyses. Make som pretty figs. Write up results. It’s early days, so jus working on the first step. However, getting a list of journals in ecology and evolution is frustratingly hard. This turns out to not be that easy if you are (1) trying to avoid Thomson Reuters, and (2) want a machine interface way to do it (read: API). ...

August 31, 2012 · 3 min · Scott Chamberlain

Making matrices with zeros and ones

So I was trying to figure out a fast way to make matrices with randomly allocated 0 or 1 in each cell of the matrix. I reached out on Twitter, and got many responses (thanks tweeps!). Here is the solution I came up with. See if you can tell why it would be slow. {% highlight r linenos %} mm <- matrix(0, 10, 5) apply(mm, c(1, 2), function(x) sample(c(0, 1), 1)) {% endhighlight %} ...

August 30, 2012 · 4 min · Scott Chamberlain

ggplot2 maps with insets

UPDATE: changed data source so that the entire example can be run by anyone on their own machine. Also, per Joachim’s suggestion, I put a box around the blown up area of the map. In addition, rgeos and maptools removed, not needed. Here’s a quick demo of creating a map with an inset within it using ggplot. The inset is achieved using the gridExtra package. Install libraries install.packages(c("ggplot2", "maps", "grid", "gridExtra")) library("ggplot2") library("maps") library("grid") library("gridExtra") Create a data frame dat <- data.frame(ecosystem = rep(c("oak", "steppe", "prairie"), each = 8), lat = rnorm(24, mean = 51, sd = 1), lon = rnorm(24, mean = -113, sd = 5)) head(dat) #> ecosystem lat lon #> 1 oak 49.58285 -107.6930 #> 2 oak 52.58942 -116.6920 #> 3 oak 50.49277 -114.5542 #> 4 oak 50.05943 -116.5660 #> 5 oak 51.76492 -112.1457 #> 6 oak 52.82153 -112.8858 Get maps using the maps library Get a map of Canada ...

August 22, 2012 · 3 min · Scott Chamberlain

Recent R packages for ecology and evolution

Many R packages/tools have come out recently for doing ecology and evolution. All of the below were described in Methods in Ecology and Evolution, except for spider, which came out in Molecular Ecology Resources. Here are some highlights. mvabund paper - get R pkg Model-based analysis of multivariate abundance data. Visualising data, fitting predictive models, checking assumptions, hypothesis testing. popdemo paper - get R pkg Population demography using projection matrix analysis. motmot paper - get R pkg Models of trait macroevolution on trees spider paper - get R pkg Analysis of species identity and evolution, with particular reference to DNA barcoding BaSTA paper - get R pkg Bayesian estimation of age-specific survival from incomplete mark–recapture/recovery data with covariates abc paper - get R pkg Approximate Bayesian Computation (ABC) RNetLogo paper - get R pkg Running and exploring individual-based models implemented in NetLogo phytools paper - get R pkg Tools for phylogenetic comparative biology smatr paper - get R pkg Estimation and inference about allometric lines RBrownie paper - get R pkg ? Testing hypotheses about rates of evolutionary change polytomy resolver paper - get R pkg Resolve polytomies on dated phylogenies with their R scripts [here][]. And a cool tool came out for the Python programming language. ...

June 14, 2012 · 2 min · Scott Chamberlain

mvabund - new R pkg for multivariate abundance data

There is a new R package in town, mvabund, which does, as they say “statistical methods for analysing multivariate abundance data”. The authors introduced the paper in an online early paper in Methods in Ecology and Evolution here, R package here. The package is meant to visualize data, fit predictive models, check model assumptions, and test hypotheses about community-environment associations. Here is a quick example (originally from https://gist.github.com/2112141) #### mvabund play # install mvabund from CRAN pkg repository install.packages("mvabund") require(mvabund) # plot abundance by copepod species data(Tasmania) attach(Tasmania) tasmvabund <- mvabund(Tasmania$copepods) plot(tasmvabund ~ treatment, col = as.numeric(block)) # fit negative binomial model for each species and plot residuals vs. fitted tas.nb <- manyglm(copepods ~ block*treatment, family="negative.binomial") plot(tas.nb) ...

March 19, 2012 · 1 min · Scott Chamberlain