EIGENSOFT : Ploteig, 3D Plots
1
1
Entering edit mode
9.4 years ago
aritra90 ▴ 70

Hi,

Is there a way to do 3d plots in EIGENSOFT, using the ploteig.perl program? I have the 2d plot of the first two principal components from EIGENSTRAT, but I need to plot the first 3 principal components in a 3d plot. I was wondering if there are other programs/software which can do this?

Any help would be much appreciated.

EIGENSOFT SNP PCA PLOT • 5.3k views
ADD COMMENT
0
Entering edit mode

Make sure you really need to plot all 3 components - how much variance they explain? 2D graphs are always simpler than 3D graphs.

ADD REPLY
5
Entering edit mode
9.4 years ago
rbagnall ★ 1.8k

You can use R with the scatterplot3d library to make a 3Dplot. Input file is the Eigensoft .evec file, which contains the first 10 principle components (I named this file vcf2eigen.pca.evec).

You can see a picture of the plot here: http://rpubs.com/rbagnall/89838

Here's the code:

library(scatterplot3d)

# read in the vcf2eigen.pca.evec file
df <- read.table("vcf2eigen.pca.evec")

# give column names
names(df) <- c("SampleID", "PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8", "PC9", "PC10", "POPULATION")

# plot
with(df, scatterplot3d(PC1, PC2, PC3, color = as.numeric(POPULATION), pch=19, main="PCA 1000 Genomes Exome Data (3D)")) 

# add legend
legend("topleft", pch=19, col=c("black", "green", "red", "blue"), legend=c("AFR", "EUR", "SAS", "EAS"))
ADD COMMENT
0
Entering edit mode

Hi,

Thanks a lot for your help. This seems to work. However, I can get the PCA plot, but, facing a lot of issues with the legends. I am very new to R, let alone, scatterplot3d nuances. I have a total of 22 populations and I want different shapes/patterns for each of them. I modified your code to something like this to make it work.

with(df, scatterplot3d(PC1, PC2, PC3, color = as.numeric(POPULATION), pch=as.numeric(POPULATION), main="PCA 3D Plot"))

Now, I can't get the legends to work, as when I give

with(df, legend("topleft", pch=as,numeric(POPULATION) col=as.numeric(POPULATION), legend=c(---22 POPULATION NAMES---))

This, doesn't seem to work. Can you help me rectify this. Again, thanks a lot for your code, the 3d scatter-plot works very well. I was trying Genesis, but it takes forever to load the data.

ADD REPLY
1
Entering edit mode

so make your plot as you have done, but add a bit more to the y margin to make space for the 22 labels

with(df, scatterplot3d(PC1, PC2, PC3, color = as.numeric(POPULATION), pch=as.numeric(POPULATION), main="PCA 3D Plot", y.margin.add=1))

then make a list of the 22 populations (this saves you having to type them out)

uniqueID <- unique(df$POPULATION)

then make the legend (change "topleft" to x, y coordinates to position it towards the top right this time. You might need to play with the position to accommodate 22 symbols )

legend(3.5, 4, pch=as.numeric(uniqueID), col=as.numeric(uniqueID), legend=uniqueID)

I have updated the plot picture http://rpubs.com/rbagnall/89838

ADD REPLY
0
Entering edit mode

Can't thank you enough ! Thanks a lot :) This is what I was looking for!

ADD REPLY

Login before adding your answer.

Traffic: 1830 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