OK, so there is a bit of a circular firing squad going on in some of my R installs with ggplot2.  Apparently, you can get various CRAN/Github versions out of sync and a whole host of different.  Here is how it started:

Read more

Intalling Shiny Server on Ubuntu 14 LTS

Intalling Shiny Server on Ubuntu 14 LTS

OK, so I just ‘found‘ shiny and it has a lot of cool stuff to it.  OK, I’ve known about it for a long time but have just had the opportunity to sit down and work it out and see how it can fit into the presentation and learning I’m trying to develop in my Applied Population Genetics online textbook.  Here is a brief overview of how I set up the shiny server on my Ubuntu box that is hosting the book (so I can embed more interactivity in the display).

Read more

Buffers & Convex Hulls

Buffers & Convex Hulls

An analysis common to modern population genetics is that of finding ecological distances between objects on a landscape.  The estimation of pairwise distance derived from spatial data is a computationally intensive thing, one that if you are not careful will bring your laptop to its knees!  One way to mitigate this data problem is to use a minimal amount raster area so that the estimation of the underlying distance graph can be done on a smaller set of points.  This example provides a simple solution using convex hulls.  Jump below for the complete example.

Read more

Raster Plotting

Raster Plotting

A raster is essentially an image, whose pixel size correspond to a particular spatial extent and the data contained within each pixel represents a particular feature on the landscape. Common rasters are DEM’s (measuring elevation), rainfall, temperature, buildings, etc. In R, it is common to think of rasters as matrices whose values measure some feature on the landscape. In this section, we will examine how to acquire, load, manipulate, and extract data from raster objects.

Read more

Merging data frames

In R, there is often the need to merge two data.frame objects (say one with individual samples and the other with population coordinates.  The merge()  function is a pretty awesome though it may take a little getting used to.
Here are some things to remember:

  1. You need to have two data.frame objects to merge
  2. The first one in the function call will be the one merged on-to the second one is added to the first.
  3. Each will need a column to use as an index—it is a column that will be used to match rows of data.  If they are the same column names then the function will do it automagically, if no common names are found in the names()  of either  data.frame objects, you can specify the columns using the optional by.x=  and by.y=  function arguments.

Read more

Loading in Rasters

Much of the work in my laboratory uses spatial data in some context.  As such it is important to try to be able to grab and use spatial data to in an easy fashion.  At present, R is probably the best way to grab, visualize, and analyze spatial data. For this example, I went to and downloaded the elevation (altitude) for tile 13 (eastern North America) as a GeoTiff.  A GeoTiff is a specific type of image format that has spatial data contained within it.  The tile data has a pixel resolution of 30 arc seconds which puts us in the general area of ~ 1km.   First, we need to get things set up to work.

Read more

Dyer RJ. 2015  Is there such a thing as landscape genetics?  Molecular Ecology.

Dyer RJ. 2015 Is there such a thing as landscape genetics? Molecular Ecology.

For a scientific discipline to be interdisciplinary it must satisfy two conditions; it must consist of contributions from at least two existing disciplines and it must be able to provide insights, through this interaction, that neither progenitor discipline could address. In this paper, I examine the complete body of peer-reviewed literature self-identified as landscape genetics using the statistical approaches of text mining and natural language processing. The goal here is to quantify the kinds of questions being addressed in landscape genetic studies, the ways in which questions are evaluated mechanistically, and how they are differentiated from the progenitor disciplines of landscape ecology and population genetics. I then circumscribe the main factions within published landscape genetic papers examining the extent to which emergent questions are being addressed and highlighting a deep bifurcation between existing individual- and population-based approaches. I close by providing some suggestions on where theoretical and analytical work is needed if landscape genetics is to serve as a real bridge connecting evolution and ecology sensu lato.


GStudio: An R Package for Spatial Analysis of Marker Data

This is the main package that provides data types and routines for spatial analysis of genetic marker data. The previous version is currently available on CRAN and you can install it rom within your R environtment by invoking the command


If you want to keep up with the latest developments of this package, you can use the version found on GitHub.  Install it from within R as:


and that should get you up-to-date.  You’ll need to have a fully working LaTeX install and some other stuff to build it if you fork.

The Users Manual for the package with several examples can be found here

I have started a github account for this package, you can get access to the whole codebase read about it on the wiki, and contribute to the project from its repo at

Extracting Data from Rasters

This document shows you how to extract data from rasters.


Getting The Libraries

First, I’ll load in some packages to get the ability to work with raster data and to load in the Arapatus attenuatus data set (it is part of the default gstudiopackage).


Loading and Cropping Rasters

We can load in the raster, and then crop it to just the are we need. These rasters were downloaded from [] and are much larger than the study area. This just makes it easier on the computer to not have to deal with such large areas. After cropping it, we will load in the annual precip and temperature data as well.


Getting Example Data from Araptus attenuatus

Now, lets grab the Araptus data and look at the data and plot out the locations.




Extracting Point Data

To elevation, temperature and precipitation from the rasters for each sampling location, we need to translate them into points first. I’ll first grab the coordinate data as a data.frame.


Then we can grab them using the normal functions in the sp library.



Plotting Trend lines.

Cool, lets sort this by latitude


and then plot out some values to look at what is going on.






Updating R and With Current Libraries

If you work in R for very long on mac, there comes a time when you upgrade and the framework process looses all your libraries!  In some sense this is pretty lame because you now have to install all these libraries again.  However, it can be a blessing if you install packages in a willy-nilly fashion as you will only reinstall the ones you use most often.  At any rate, it is kind of a pain.  Here is what I’ve been doing about this to automate the process.  The key here is that you need to do the first part before you upgrade.

Current Library

In the old version of R, prior to updating you’ll want to save the libraries that you have installed.  In R, this can be done as follows:


Install Updated R Version

Either download the latest package or update your svn repository and rebuild R and install it.  There are a lot of options for learning more about these options elsewhere on the web.

Install Missing Packages

Now, in the new version of R, you can figure out which are installed by default and then take the differences from what you have and what the previous version had installed and then install them.


And you should be done.