[adegenet-forum] interpolation in contour plots of spca

Jombart, Thibaut t.jombart at imperial.ac.uk
Sun Jul 19 19:32:27 CEST 2009

Dear Collin,

sorry for not replying before. Weirdly enough, I did not receive this post, and happened to see it by luck while checking the archives.
> Hello Thibaut and List,
> I have a few questions regarding plotting and interpreting an spca.  Our data set consists of georeferenced individuals unevenly sampled in space and genotyped at nuclear microsatellite loci.  Because the samples are unevenly distributed I chose the inverse distance connection network (option 7).   We have a few interpretable global axes and for our situation the contour plot with s.image seems to be a nice display.  The code I have used for the following questions is pasted below the main body of the text. 
> My main question is how is empty space interpolated in this plot (s.image) and can I alter the method if needed?  I am getting some peripheral contours where there is no data which may be expected depending on how the data are being interpolated.  I can "fix" this by increasing the value for the "span" argument (degree of smoothing) from the default of 0.5 but I am not entirely clear what the "span" argument is actually altering.  Would increasing span be generally appropriate given that I have unevenly distributed samples and I am looking at global axes of variation?  As I alter span the plot certainly changes.  For a given sample size and scheme, is there a rule of thumb to choose the most 'honest' span value for this type of plot with genetic data? 

The span argument is passed to the loess function, which is used for predicting values of the variable (here, a principal component of sPCA) as a function of x and y coordinates using a local regression. 'span' is used to set the size of the 'neighbourhood' used in the local regression process. There is not much more in the loess documentation, but you might want to have a look to the 'details' section in ?loess. There may be insights about that topic on usual R lists (RSiteSearch("span loess") gives a few answers, but I'm not sure about their relevance).

> My next question involves adding individual samples to the plot.  I suspect this is easy but I'm stuck.  I have plotted the figure on a map outline of the area (using the area argument) but can't seem to plot individuals on the map.   

Well, any function adding elements to a plot, such as 'points', should do. You can also use s.[...] (eg s.value, s.labels, ...) specifying add.p=TRUE. In some cases you may want to extend the plotting area to the whole figure. To do so, use :
before adding elements to the graphics.

> I understand that all of my questions can be handled in a GIS but I am interested in learning the R way.

Good idea. ;-)

> Thanks very much for any help.
No probs, sorry again for the delay.



> Colin
> library(adegenet)
> library(ade4)
> library(adehabitat)
> library(rgdal)
> ##Reads genetic and location data
> ds1<-read.structure("APPHybridFinalJune2009sPCAInput.stru", n.ind=217, n.loc=12,  onerowperind=T, col.lab=1, col.pop=2, col.others=0, row.marknames=0, NA.char="-9", missing=NA, ask=TRUE, quiet=FALSE)
> xy<-read.table("xy.txt", header = T)
> ##Reads in shape file and converts it to area object
> ont<-readOGR("C:\\Documents and Settings\\Colin\\Desktop\\Wolf", "ONTARIO")
> areaont<-spol2area(ont)
> ##Performs and plots spca on shape file
> mySpca2 <- spca(ds1, type = 7, ask = FALSE, scannf = FALSE, xy = xy, nfposi = 8, nfnega = 8)
> s.image(xy,mySpca2$li[,1], include.ori = FALSE, grid = F, kgrid = 30, cgrid = 0, sub = "1st global axis", csub = 1.25, possub = "topleft", area = areaont)
> -- 
> Colin Garroway (PhD candidate)
> Wildlife Research and Development Section
> Ontario Ministry of Natural Resources
> Trent University, DNA Building
> 2140 East Bank Drive
> Peterborough, ON, K9J 7B8
> Canada
> http://colin.garroway.googlepages.com/home
> _______________________________________________
> adegenet-forum mailing list
> adegenet-forum at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/adegenet-forum

Dr Thibaut JOMBART
MRC Centre for Outbreak Analysis and Modelling
Department of Infectious Disease Epidemiology
Imperial College - Faculty of Medicine
St Mary’s Campus
Norfolk Place
London W2 1PG
United Kingdom
Tel. : 0044 (0)20 7594 3658
t.jombart at imperial.ac.uk

More information about the adegenet-forum mailing list