[adegenet-forum] Visualizing DAPC with scatter() - help

Zhian Kamvar zkamvar at gmail.com
Sat Apr 25 17:33:24 CEST 2020


Hello,

There's not really an easy way to do this with the scatter function. It does not assume that you want to color each individual independently. Something that might help is the fact that the coordinates for the discriminant axes are stored in the '$ind.coord' section of the DAPC object. You shouldn't need to run DAPC twice to color the output by the original populations. I you have a palette that defines the colors for each population, then you can use the population assignments (found with the pop() function) to create a vector of colors for each individual. 

If it helps, back in 2017, I created a function called ggscatter to help split the DAPC by different population factors, which might make a better visualization than coloring the points by population of origin: https://github.com/everhartlab/sclerotinia-366/blob/8f309a9169e26d964d7978ac8f636bb6270724bc/results/by-year.md#dapc

Hope that helps.

Best,
Zhian

> Date: Sun, 22 Mar 2020 12:38:22 -0500
> From: Kathryn Davis <daviskec at gmail.com>
> To: adegenet-forum at lists.r-forge.r-project.org
> Subject: [adegenet-forum] Visualizing DAPC with scatter() - help
> Message-ID:
> 	<CAMXAJG1dWiHp8+5UocCg+70PaiMUh9FU0dNKjrPpPRoBYPn5bA at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
> 
> Hello all,
> 
> I am trying to visualize a DAPC based upon the four clusters identified by
> find.clusters() in a previous step. However, I want the color of points to
> correspond to the origin of the individual (be it sampling site, presumed
> subspecies, or another data point). A collaborator told me to use setPop()
> and the scatter() code listed below. While this produced a DAPC plot with
> each subspecies represented as a cluster, each with their own color, the
> clusters do not line up to those in the DAPC plot with find.clusters input.
> 
> I've included my code below. Any suggestions on how to plot what I would
> like will be greatly appreciated (I would also, once I have things working
> the way I want, like to be able to manipulate the colors of the subspecies
> to match other figures).
> 
> # START HERE create genlight object, name samples
> n_gl <-vcfR2genlight(vcfile)
> indNames(n_gl)<-plot_info$Sample
> 
> #replace NAs
> mydf<-lapply(n_gl, as.integer)
> n_gl_2<-do.call(rbind, lapply(mydf, function(e) replace(e, is.na(e), 0)))
> n_gl_2<-as.genlight(n_gl_2)
> 
> #define strata/populations
> strata.df <- read.table("pop-info.csv", header = TRUE, sep = ",")
> strata(n_gl_2) <- strata.df
> setPop(n_gl_2) <- ~Coast/Subspecies
> popNames(n_gl_2)
> 
> #run find.clusters how many PCs/DAs to include
> find.clusters(n_gl_2) #tutorial recommends keeping all PCs (300)unless it
> is too computationally expensive. Identify the number of clusters as the
> lowest BIC value (4)
> grp<- find.clusters(n_gl_2, n.pca=300, n.clust=4)
> 
> #run DAPC directly:
> dapc1 <- dapc(n_gl_2, n.pca=150, n.da=6) #without prior clusters
> 
> dapc2 <- dapc(n_gl_2, grp$grp, n.pca=150, n.da = 3) #with prior clusters,
> number of PCs=150, DAs=3
> 
> ##plot
> scatter(dapc1, scree.da=FALSE, bg="white", pch=20, cell=1, cstar=1,
> solid=.6, cex=2, clab=0, legend=TRUE, posi.leg="topleft")
> scatter(dapc2, scree.da=FALSE, bg="white", pch=20, cell=1, cstar=1,
> solid=.6, cex=2, clab=0, legend=TRUE)
> 
> Thank you,
> 
> -- 
> Katie Davis
> Louisiana State University '20
> Natural Resource Ecology & Management/Spanish Major
> daviskec at gmail.com | 407-927-6696
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20200322/3c8676e7/attachment-0001.html>
> 
> ------------------------------
> 
> Subject: Digest Footer
> 
> _______________________________________________
> 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
> 
> ------------------------------
> 
> End of adegenet-forum Digest, Vol 136, Issue 8
> **********************************************



More information about the adegenet-forum mailing list