Question: ADMIXTURE and R, color meaning on barplot in studing population ancestry, K value
gravatar for dirranrak
3.2 years ago by
United States
dirranrak10 wrote:

Hi all, I advanced using ADMIXTURE after using Plink and I have got K=5, so I ploted the data with R using col=5. I get the barplot with each bar representing an individual but how can I recognize the color label such as the red color for example and/or which population? because the *.5.Q file just has row or column for the proportions and each individual. Thank you.

R gene • 6.1k views
ADD COMMENTlink modified 7 months ago by edison.vazquez0 • written 3.2 years ago by dirranrak10

The key to generating the canonical admixture plots in R is to used a stacked barplot with the coancestry coefficients. Is this what you're doing? It's not clear.

ADD REPLYlink written 3.2 years ago by Brice Sarver2.5k

This is the plot from myfile.5.Q using R. I try to find what does mean each color (ancestry population probably? and if it is the case, which population?).

Here is the way I did it:

> tbl=read.table("trialmergedexcludedrs3926405,rs365066AfricaKhoisanexcludedsnpwith0phenotypegeno0.05hwe0.001Batwa_Kiga.913651pos.230samples.PNAS2014_trial1_flip.5.Q")
> barplot(t(as.matrix(tbl)), col=rainbow(5),
+ xlab="Individual", ylab="Ancestry", border=NA)

ADD REPLYlink written 3.2 years ago by dirranrak10

Hi, so the thing that I try to do with plink, admixture, and R is to find the ancestry(ies) of some populations in my genomic data.

I just got the proportions for each individual with ADMIXTURE and I ploted these files in R using K=2 to K=5. After that, the plot that I got are with different colors depending on K value, so the first one is with 2 colors and the last one is with 5 colors. the question is now, how can I Know the meaning of each color in each individual proportion?

Thank you so much.


ADD REPLYlink written 3.2 years ago by dirranrak10

Hello, did you find something?

Thank you.

ADD REPLYlink written 7 months ago by edison.vazquez0
gravatar for Zev.Kronenberg
3.2 years ago by
United States
Zev.Kronenberg11k wrote:

I just finished writing an set of functions for admixture plotting:


after sourcing the file point the R function at the directory containing the *.Q and *.fam


to access subplot 5  :

ADD COMMENTlink written 3.2 years ago by Zev.Kronenberg11k


I tried using the function but ran into following error (the last line). Is it something that i'm doing wrong?

Loading required package: reshape2
Loading required package: grid
Loading required package: ggplot2
Find out what's changed in ggplot2 at
Loading required package: plyr
Loading required package: RColorBrewer
Error in file(file, "rt") : invalid 'description' argument


ADD REPLYlink written 2.8 years ago by akang90

looks like the function is having trouble finding the files.  What are the file extensions? 

ADD REPLYlink written 2.8 years ago by Zev.Kronenberg11k

Standard output files of admixture plus a .fam file (Folder contains File.1.Q to File.10.Q & File.fam). Along with that the folder also has the results of admixture analysis of a different dataset. Could that be a problem? Is there a way to specify a particular inputfile?

ADD REPLYlink modified 2.8 years ago • written 2.8 years ago by akang90

Right now no. It should would if you separate the runs into different folders.  Feel free to change the [R] code to specify an input.  

ADD REPLYlink modified 2.8 years ago • written 2.8 years ago by Zev.Kronenberg11k

Thanks Zev! 

ADD REPLYlink written 2.8 years ago by akang90

I moved the results to a different directory and now i get this error: In levels<-(*tmp*, value = if (nl == nL) as.character(labels) else paste0(labels, : duplicated levels in factors are deprecated How to resolve this?

ADD REPLYlink written 2.8 years ago by akang90

Can you send me a test dataset?

ADD REPLYlink written 2.8 years ago by Zev.Kronenberg11k

@Zev,here is the test data

ADD REPLYlink modified 2.7 years ago • written 2.8 years ago by akang90

@Zev.Kronenberg The code worked once and but gives an error when I ran it the second time. I do not understand why.I tried plotting the same files, it ran fine once though

Error in data.frame(..., check.names = FALSE) : 
arguments imply differing number of rows: 0, 190
Error: with piece 1:
ADD REPLYlink modified 2.7 years ago • written 2.7 years ago by akang90

Hi Zev,

Thank you for the code. I was busy to understand learning coding other stuff. But now when I try to run your code in R, even just at the beginning I got the error below. And if I remove the quote when specifying the directory, the rest of the code becomes comment.

plot.admixture<-function("~/Documents/admixture_macosx-1.23") Error: unexpected string constant in "plot.admixture<-function('~/Documents/admixture_macosx-1.23'"

Do you have an idea why this happen?

ADD REPLYlink written 2.6 years ago by dirranrak10

Dear Zev, Thank you. I managed to get the admixture plot using your script. However, the x-axis has the individual samples names. Could it be possible to show the population group as well? the fam file looks the below way where the las column says the group.

`AC065 AC065 0 0 0 -9 G1
 AM236B1 AM236B1 0 0 0 -9 G1
 BB011 BB011 0 0 0 -9 G2
 BC1021 BC1021 0 0 0 -9 G3
 BC1026 BC1026 0 0 0 -9 G3`

The current script has the sample names from the second column on X-axis. Could it also include the group names to visualize both the sample names and the group to which it belongs to?

ADD REPLYlink modified 2.5 years ago • written 2.5 years ago by hellbio340
gravatar for edison.vazquez
7 months ago by
edison.vazquez0 wrote:

Dear Dirrank,

did you find the answer to your question?, because I'm in the same situation.

Thank you.

ADD COMMENTlink written 7 months ago by edison.vazquez0

Dear edison.vazquez, you can try to use a new R packege called BITE. We have implemented 2 different functions to plot Admixture results.

ADD REPLYlink written 6 months ago by Marco.Milanesi0
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1315 users visited in the last hour