[adegenet-forum] colorplot and scatter

Jombart, Thibaut t.jombart at imperial.ac.uk
Thu Aug 20 16:50:43 CEST 2015


Hi there

thanks for reposting to the group.

In two dimensions, it is easier to get a legend. To get the basic one:

library(adegenet)
xy <- expand.grid(1:30,1:30)
colorplot(xy, xy, pch=15, cex=10, xlab="Axis 1", ylab="Axis 2")

You can have better resolution by replacing 30 by a larger number.
You can add the legend manually afterwards, or using add.scatter:

m1=matrix(rnorm(200),ncol=2)
m2=matrix(rnorm(200),ncol=2)
colorplot(m1,X=m2, xlab="x", ylab="y", cex=2)
add.scatter({par(xaxt="n",yaxt="n");colorplot(xy, xy,xlab="Axis 1",ylab="Axis 2", line=0)})

Cheers
Thibaut



________________________________
From: BICHET CORALINE [coraline.bichet at univ-lyon1.fr]
Sent: 20 August 2015 15:14
To: Jombart, Thibaut; adegenet-forum at lists.r-forge.r-project.org
Subject: RE:colorplot and scatter

Dear Thibaut

Thanks à lot!

The script for the scatter works very well!

I give more precisions about my problem with the function colorplot.
My sPCA in only defined with two axes:

>spca1
########################################
# spatial Principal Component Analysis
#########################################
class: spca
$call: spca(obj = geno, xy = coord, scale = TRUE)

$nfposi: 2 axis-components saved
$nfnega: 0 axis-components saved
Positive eigenvalues: 9.571 6.744 4.421 3.258 2.818 ...
Negative eigenvalues: -0.1399 -0.09504 -0.09378 -0.08205 -0.0807 ...

  vector length mode    content
1 $eig   123    numeric eigenvalues

  data.frame nrow ncol content
1 $c1        140  2    principal axes: scaled vectors of alleles loadings
2 $li        310  2    principal components: coordinates of entities ('scores')
3 $ls        310  2    lag vector of principal components
4 $as        2    2    pca axes onto spca axes

$xy: matrix of spatial coordinates
$lw: a list of spatial weights (class 'listw')

other elements: NULL

And the colorsplot function is:
colorplot(spca1$xy, spca1$ls, axes = 1:2, cex = 3)

If I understand well the function, the colorplot projects my populations according to their geographical coordinates and adds a color (green-red scale) according to the ls score for the twa sPCA axes.
The spca1$ls object contains two columns corresponding to the ls of the two axes:

> head(spca1$ls)
    Axis 1    Axis 2
1 3.383404 -2.599413
2 3.401930 -2.626953
3 3.410790 -2.636643
4 3.376684 -2.647047
5 3.368616 -2.582604
6 3.385992 -2.636117

So what I want to do is add the legend of these colors ...
I ask again because I'm not sure that I was clear the first time
I'm sorry to ask you again, but even my colleagues who usually save me with R have never used this colorplot ...

Thank you again!

Coraline Bichet
coraline.bichet at univ-lyon1.fr
+33(0)472433584
UMR-CNRS 5558, Laboratoire de Biométrie et Biologie Evolutive (LBBE)
Université Claude Bernard Lyon 1, bâtiment Mendel
43 boulevard du 11 novembre 1918
69622 Villeurbanne Cedex, FRANCE

________________________________
De : Jombart, Thibaut [t.jombart at imperial.ac.uk]
Envoyé : jeudi 20 août 2015 13:01
À : BICHET CORALINE; adegenet-forum at lists.r-forge.r-project.org
Objet : RE: colorplot and scatter

Hi Coraline

The colorplot is basically translating up to 3 quantitative variables into colors using RGB coding. So each axis corresponds to a channel, but the problem is our eyes are not good at knowing what color comes out when combining values RBG channels. To have a proper legend for 3 axes we would need some kind of color triangle. And a different system for 2 axes.. nothing impossible to code, but cumbersome.

As for your second question, your approach is the best way to go. But there's a trick.
The function add.scatter.eig, which adds the barplots of eigenvalues to the plot, changes the coordinate system, so that you can't plot anything afterwards. You need to disable them,e g.:

library(adegenet)
example(dapc)
scatter(dapc1, col="transparent", scree.da=FALSE)
points(dapc1$ind.coord[,1],dapc1$ind.coord[,2], col=funky(100))

Note that if some points are missing around the edges, you may need a par(xpd=TRUE) right before your 'points(..)'.

Cheers
Thibaut

==============================
Dr Thibaut Jombart
MRC Centre for Outbreak Analysis and Modelling
Department of Infectious Disease Epidemiology
Imperial College - School of Public Health
Norfolk Place, London W2 1PG, UK
Tel. : 0044 (0)20 7594 3658
http://sites.google.com/site/thibautjombart/
http://sites.google.com/site/therepiproject/
http://adegenet.r-forge.r-project.org/
Twitter: @thibautjombart


________________________________
From: adegenet-forum-bounces at lists.r-forge.r-project.org [adegenet-forum-bounces at lists.r-forge.r-project.org] on behalf of BICHET CORALINE [coraline.bichet at univ-lyon1.fr]
Sent: 20 August 2015 10:29
To: adegenet-forum at lists.r-forge.r-project.org
Subject: [adegenet-forum] colorplot and scatter

Dear forum

I have two questions about the adegenet functions "colorplot" and "scatter"
I precise that I am a beginner with the package adegenet, so excuse me in advance if my questions seem a little stupid...

1. Colorplot

I made a colorplot to represent the result of a sPCA. The colorplot plots the different populations according to their localisation and the colors correspond to the global sPCA score. I would like to add a legend in a box representing the correspondance between colors and sPCA score (as the image below). I search... but I did not find anything to do this...


[cid:426d0c7f-6e00-4dd2-a001-eeab8f80089a]


2. Scatter

I used the function scatter to represent the results of a DAPC. The colored dots in the plot represent the cluster, but I would like to know if it is possible that the dots represent populations instead of clusters. The clusters would be still represented with the colored bars and the ellipses. I only want to change the dot colors. I tried to manually add dots in the plot (with the function "points"), using the coordinates of each indviduals in the DAPC axes. But the dots did not appeared... maybe due to a scale problem that I cannot solve...
Here the function that I use for one population. The data frame "ind" contains the DAPC LD1 and LD2, and the population names of the different individuals :

points(ind$LD1[ind$pop=="Aussois"]), scale(ind$LD2[ind$pop=="Aussois"]), col="black", pch=16, cex = 1)


I hope that my questions are comprehensible. Thank you very much in advance for your help. Don't hesitate to let me know if you need further information to more understand my problems.

Thanks a lot!

Coraline Bichet
coraline.bichet at univ-lyon1.fr
+33(0)472433584
UMR-CNRS 5558, Laboratoire de Biométrie et Biologie Evolutive (LBBE)
Université Claude Bernard Lyon 1, bâtiment Mendel
43 boulevard du 11 novembre 1918
69622 Villeurbanne Cedex, FRANCE

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20150820/0b56f211/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: box.jpg
Type: image/jpeg
Size: 5902 bytes
Desc: box.jpg
URL: <http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20150820/0b56f211/attachment-0001.jpg>


More information about the adegenet-forum mailing list