You may be familiar with the classic GRADISTAT for calculating particle size statistics. It is a set of macros written into a Microsoft Excel spreadsheet by Kenneth Pye and Simon Blott. At the time of writing it was last updated for use with Microsoft Excel 2007, and is becoming increasingly difficult to use with newer versions of Excel. After recently troubleshooting some odd GRADISTAT outputs for one of our lab users, I decided to see if there were alternatives available.

G2SD, written by Regin Gallon and Jerome Fournier, does everything GRADISTAT did and a little more, and all as an easy to use package in R. Easy to use R? I hear you ask! Well yes, because it has the option of using a web-based interface (built using the “shiny” R package). I’m (very) still starting out with R, and I’m not finding it easy! However, this package can be used with minimal knowledge – just follow my instructions below. *Want to try it out first, or only need basic functionality? Why not use the hosted web-based version, available here for use with delimited text files (e.g. *.csv, *.tab).*

**Install R and G2Sd**

- Assuming you are a Windows user, visit the R website, download and run the installation file, selecting the default options.
- Visit the repository for G2Sd and download the latest stable version.
- Open RGui, and from the top navigation menu, select Packages>Install Packages From Local Files.
- Navigate to the downloaded *.zip file that contains G2Sd files.
- G2SD is dependent on some other packages. Install the first by typing install.packages(“shiny”).
- Repeat step five but replace shiny with xlsx, then rJava, xlsxjars, reshape2 & ggplot2.
*You only need to do this once!*

**Loading and Using G2Sd**

- Load G2Sd by typing library(G2Sd), or by navigating Packages>Load Packages>G2Sd from the top navigation menu.
- Run the web browser based GUI by typing granstat(web_interface=TRUE). A web-browser should appear!
- The data should be in the format:
- The first column are the sieve mesh sizes in microns, in descending order (from largest to smallest aperture). Size “0” is the pan.
- Columns subsequent to the first are a sample. The first row is the sample identifier.

- From here you can visualise and download the data.

**Using the Command Prompt Instead**

- Load G2Sd as previously described.
- Load CSV data into an R dataframe by typing mydata <- read.table(“mydata.txt”, header=TRUE, sep=”,”). If you don’t have your own data, an example dataset is included in the package. Try loading it using data(granulo), and exporting it to a CSV datafile using write.table(granulo, “granulo.txt”, sep=”,”).
- For statistics, try typing granstat(mydata). There’s a lot more functionality here – check out the package documentation for more.
- If you want to export these to a CSV file, just combine the two functions we met previously: type write.table(granstat(mydata), “mydata.txt”, “sep=”,”).
- For graphics, try trying grandistrib(mydata). There’s options for multiple samples to be plotted, and a number of different styles – try granplot(mydata) or granplot(mydata, xc=2:4) for a couple of examples. Check out the package documentation for more.
- To export a graphic generated in the data frame, right click the figure and save using the dialog box.

References:

**Blott, S.J. & Pye, K. (2001).** “GRADISTAT: a grain size distribution and statistics package for the analysis of unconsolidated sediments”. *Earth Surface Processes and Landforms* v26, pp.1237-1248.

**Fournier J., Gallon R. (2014).** “G2Sd: a new R package for the statistical analysis of unconsolidated sediments”. *Géomorphologie : relief, processus, environnement* v20(1), pp.73-78.