gstudio: Spatial Analysis of Genetic Marker Data

Author

Rodney J. Dyer

Published

October 5, 2026

Preface

The gstudio package provides a comprehensive set of tools for the spatial analysis of genetic marker data in R. Originally developed to support research in landscape genetics and population genomics, it offers a unified framework for estimating genetic diversity, population structure, inter-individual and inter-population distances, relatedness, and population graph topology.

At the core of the package is the locus S3 class, a flexible representation of genotypes that supports codominant markers, SNPs, AFLPs, and allozymes. Built around this data type, gstudio provides four main analytical entry points — genetic_diversity(), genetic_structure(), genetic_distance(), and genetic_relatedness() — each dispatching to a range of estimators. Population Graphs, a graph-theoretic approach to understanding among-population connectivity (Dyer & Nason 2004), are fully integrated with construction, analysis, and visualization tools.

Who This Book Is For

This book is intended for population geneticists, landscape ecologists, and conservation biologists who want to analyze genetic marker data in R. It assumes basic familiarity with R and introductory population genetics concepts.

How to Use This Book

Each chapter is self-contained and can be read independently, though they build on each other sequentially. Code examples use live R execution, so you can follow along by running the code in your own R session.

Quick Start

library(gstudio)
library(dplyr)
data(arapat)

arapat |>
  glimpse()
Rows: 363
Columns: 14
$ Species    <fct> Peninsula, Peninsula, Peninsula, Peninsula, Peninsula, Peni…
$ Cluster    <fct> NBP-C, NBP-C, NBP-C, NBP-C, NBP-C, NBP-C, NBP-C, NBP-C, NBP…
$ Population <fct> 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 9, 9, 9, 9, 9, 9, 9…
$ ID         <fct> 88_11A, 88_12A, 88_13A, 88_14A, 88_15A, 88_16A, 88_17A, 88_…
$ Latitude   <dbl> 29.32541, 29.32541, 29.32541, 29.32541, 29.32541, 29.32541,…
$ Longitude  <dbl> -114.2935, -114.2935, -114.2935, -114.2935, -114.2935, -114…
$ LTRS       <locus> 01:01, 01:01, 01:01, 01:01, 01:01, 01:01, 01:01, 01:01, 0…
$ WNT        <locus> , 01:03, 01:03, 01:01, 01:03, 01:01, 01:01, 01:01, 01:03,…
$ EN         <locus> 02:04, 01:01, 01:01, 01:02, 01:02, 01:02, 01:02, 01:02, 0…
$ EF         <locus> 01:02, 01:01, 01:01, 01:01, 01:01, 01:01, 01:01, 01:01, 0…
$ ZMP        <locus> , 01:01, 01:01, 01:01, 01:01, 01:01, 01:01, 01:01, 01:01,…
$ AML        <locus> , 08:09, 08:09, 08:09, 08:09, 09:09, 07:09, 07:07, 09:10,…
$ ATPS       <locus> 09:09, 09:09, 09:09, 09:09, 09:09, 09:09, 09:09, 09:09, 0…
$ MP20       <locus> 07:07, 07:07, 05:07, 07:07, 05:05, 07:07, 05:07, 05:07, 0…

The arapat dataset contains multilocus microsatellite genotypes from the cactus beetle Araptus attenuatus and will serve as the primary example dataset throughout this book.

arapat |>
  head()
    Species Cluster Population     ID Latitude Longitude  LTRS   WNT    EN
1 Peninsula   NBP-C         88 88_11A 29.32541 -114.2935 01:01       02:04
2 Peninsula   NBP-C         88 88_12A 29.32541 -114.2935 01:01 01:03 01:01
3 Peninsula   NBP-C         88 88_13A 29.32541 -114.2935 01:01 01:03 01:01
4 Peninsula   NBP-C         88 88_14A 29.32541 -114.2935 01:01 01:01 01:02
5 Peninsula   NBP-C         88 88_15A 29.32541 -114.2935 01:01 01:03 01:02
6 Peninsula   NBP-C         88 88_16A 29.32541 -114.2935 01:01 01:01 01:02
     EF   ZMP   AML  ATPS  MP20
1 01:02             09:09 07:07
2 01:01 01:01 08:09 09:09 07:07
3 01:01 01:01 08:09 09:09 05:07
4 01:01 01:01 08:09 09:09 07:07
5 01:01 01:01 08:09 09:09 05:05
6 01:01 01:01 09:09 09:09 07:07

Code in this book is written as pipelines, one function per line; every function also works with its options passed as arguments (see Code Style in This Book in the next chapter).

Citation

If you use gstudio in your research, please cite:

Dyer, R.J. 2009. GStudio: a suite of tools for the spatial analysis of genetic marker data. Molecular Ecology Resources 9(1): 110-113.

Source Code

The source code for gstudio is available on GitHub at https://github.com/dyerlab/gstudio.