Generating an MDS plot in R for population stratification
0
0
Entering edit mode
3.1 years ago
nliberman • 0

Hello,

I'm very new to bioinformatics and I'm just starting out using PLINK and R to perform a GWAS for the first time. I've generated a .mds file through PLINK of 10 dimensions that looks like this file:

With many more rows of course. I'm trying to graph an MDS plot of this data but I'm not sure how? I found this code online:

m <- read.table('pca.mds', header = TRUE)
m <- as.matrix(m[, 4:13])
mds <- cmdscale(as.dist(1-m))
plot(mds)

But this generates the error:

non-square matrixnumber of items to replace is not a 
multiple of replacement length
Error in dimnames(points) <- list(rn, NULL) : 
length of 'dimnames' [1] not equal to array extent

Can someone help explain why this is happening and how to fix it? I'm very new to this, and I'd like to generate a plot that looks like:

sample mds plot

Probably with more dimensions though obviously. Or I'm not really sure if there's a better way to generate an MDS plot for the purposes of population stratification? Any help would be much appreciated!

R MDS Stratification PCA PLINK • 1.2k views
ADD COMMENT
0
Entering edit mode

Please do not paste screenshots of plain text content, it is counterproductive. You can copy paste the content directly here (using the code formatting option shown below), or use a GitHub Gist if the content volume exceeds allowed length here.

code_formatting

ADD REPLY
0
Entering edit mode

Thank you for the tip! Fixed :)

ADD REPLY
0
Entering edit mode

Thank you for bettering your post!

There was one step that needed to be done a little differently: the gist link must be pasted directly in the text and not using the Hyperlink option on the toolbar. Doing it the former way embeds the gist in the post.

ADD REPLY

Login before adding your answer.

Traffic: 2403 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6