Wednesday, 16 March 2011

Textural triangle plot in R

these days I'm working with soil textural data and one of the key point of these data is the presentation of the results.
The best way is a old-school texture triangle!!!

Because I like to do all my stuff in R, instead of opening draw software such as corel draw or adobe illustrator, I started looking at packages for this kind of plot.

I think the best one is plotrix, because it let's you plot the USDA or UK textura triangle, so in the end the image is ready for publication.

I prepared a little script to show how to create a simple plot, adding the legend and save it as image file.
The script is downloadable from this link:
R script

I'm also preparing a little video for showing how to use the script but if you are familiar with R, you don't need it.

Friday, 11 March 2011

Script for Geostatistics with R

I received requests for the script used during the tutorial.
All the material is available in the main page of the course.
However, in order to facilitate the availability of the scripts to all the viewers of this blog I've put the link to donwnload them at the end of this post.

This zip file contains 3 R scripts:
- Lesson3: How to handle and plot spatial data in R
- Lesson4: How to perform an Ordinary Kriging with gstat
- Lesson5: How to perform a Universal Kriging with gstat

And here is the link:
R script

Thursday, 3 March 2011

3D Anisotropy parameters

Hello everyone,

I’m trying to create a method for calculating the 5 parameters for the 3D anisotropy in an automatic way.

Basically I created a loop for analysing the range of the horizontal variogram in every direction and extrapolating the maximum (for the angle p). Then it computes the vertical variogram in the direction of maximum continuity and extrapolates the maximum range (for the angle q).

Subsequently, it computes the vertical variogram for the direction of minimum continuity (angle of max continuity + 90), and extrapolates the maximum (for the angle r).

Ultimately, it calculates the ratio between the range of the maximum continuity and the other 2.

I would like to know what the community think of this idea.

Could you please tell me if it makes sense and, if it does, how to improve it?

So far I wrote the following lines:

library(gstat, pos=4)

library(sp, pos=4)



##a covariate that will be used to specify the cutoff of the variogram


##Data format:

## Lat = latitude

## Lon = longitude

## depth = depth

## value = data value



##First Loop for angle p



for(i in 0:180){






##Second Loop for angle q



for(i in 0:180){






##Third Loop for angle r



for(i in 0:180){












R Video Tutorial for Spatial Statistics

Welcome everybody, this is a video tutorial that will try to teach you how to use R for spatial statistics and interpolation.

I’m a PhD student in soil science and in particular my project is about digital soil mapping. During my work I often use R particularly for geostatstical interpolation. Despite R being a very powerful statistical language which has became a benchmark for spatial statistics, it is also a relatively difficult language to learn with one of the steepest learning curve among programming languages.

For this reason I though about sharing what I’ve learned during my PhD with all the R community. I prepared this video tutorial because I think that the easy way of learning R is by examples.

The tutorial is structured as follow: the first two lesson are about the basics of R, how to handle R objects, plotting and saving your work. This part is intended for a beginner user who want to learn the language. Starting from the third lesson I will show examples on how to handle and plotting spatial data and rasters, and in the last two lesson I will show you how to perform an ordinary and a universal kriging in R.

In this tutorial I will show you some example that will hopefully help you learning R in a quicker and easier way. However, this course is not a complete R course, because R has lots and lots of different functions for every branch of science. For this reason at the beginning of the course and at the end of the lesson, if appropriate, I will give you some references if you want to deepen your knowledge.

The link to the course is here:

If you have any suggestion at all on how to improve the course or any other feedback, send an e-mail to: