# open an example dataset (HapMap)
genofile <- snpgdsOpen(snpgdsExampleFileName())
# perform identity-by-state calculations
ibs <- snpgdsIBS(genofile)
# perform multidimensional scaling analysis on
# the genome-wide IBS pairwise distances:
loc <- cmdscale(1 - ibs$ibs, k = 2)
x <- loc[, 1]; y <- loc[, 2]
race <- as.factor(read.gdsn(index.gdsn(genofile, "sample.annot/pop.group")))
plot(x, y, col=race, xlab = "", ylab = "", main = "cmdscale(IBS Distance)")
legend("topleft", legend=levels(race), text.col=1:nlevels(race))
# close the file
snpgdsClose(genofile)
Run the code above in your browser using DataLab