Question: EIGENSOFT : Ploteig, 3D Plots
1
Entering edit mode
5 months ago
aritra90 • 40
United States

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.

ADD COMMENTlink 4.2 years ago aritra90 • 40 • updated 5 months ago ravikumardhanapal • 0
Entering edit mode
0

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

ADD REPLYlink 4.2 years ago
PoGibas
4.8k
5
Entering edit mode
4.2 years ago
rbagnall ♦ 1.4k
Australia

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 COMMENTlink 4.2 years ago rbagnall ♦ 1.4k
Entering edit mode
0

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 scatterplot works very well. I was trying Genesis, but it takes forever to load the data.

ADD REPLYlink 4.2 years ago
aritra90
• 40
Entering edit mode
1

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 REPLYlink 4.2 years ago
rbagnall
♦ 1.4k
Entering edit mode
0

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

ADD REPLYlink 4.2 years ago
aritra90
• 40

Login before adding your answer.

Powered by the version 1.5