so i dont have to do the PCA first and use the file i can directly import my data file and your tool can do PCA and visualise the data?
Im trying to make a 3D PCA but i m not sure if its really working or not i cannot label my sample which i intend to here is my code anyone can help or any suggestion how can i label my samples in my final plot.
d <- read.csv("~/analysis/gene_fpkm/PRIMARY_AUX_ATPASE.csv",header = TRUE)
names(d)
model <- prcomp(t(d[,-1]), scale=TRUE)
plotPCA <- function(x, nGroup) {
n <- ncol(x)
}
fit <- hclust(dist(x), method="complete")
groups <- cutree(fit, k=nGroup)
if(n == 3) { # 3d plot
plot3d(x, col=groups, type="s", size=1, axes=F)
axes3d(edges=c("x--", "y--", "z"), lwd=3, axes.len=2, labels = TRUE)
mtext3d(text)
grid3d("x")
grid3d("y")
grid3d("z")
} else { # 2d plot
maxes <- apply(abs(x), 2, max)
rangeX <- c(-maxes[1], maxes[1])
rangeY <- c(-maxes[2], maxes[2])
plot(x, col=groups, pch=19, xlab=colnames(x)[1], ylab=colnames(x)[2], xlim=rangeX, ylim=rangeY)
lines(c(0,0), rangeX*2)
lines(rangeY*2, c(0,0))
}
}
plotPCA(model$x[,1:3], 5)
this is the code im running i cannot label my sample in which comes in the final 3D pca .any suggestion or help would be highly appreciated
3 answers
This is a question more suited to an R programming forum. Anyway, I suggest you look into the car package and its scatter3d() function (hint: look for the labels parameter). Otherwise, with rgl, you need to use the text3d() function. The statistical tools for high-throughput data analysis (STHDA) web site has tutorials on 3D graphics in R (among other useful tutorials).
Here's a tutorial I wrote using the rgl package mentioned by Jean. It includes 3D labels, exporting and animating. Hope it helps!
To save the effort of writing code to visualize PCA results and other 3D datasets, I wrote a tool called Cubemaker that imports tab-delimited matrix files and renders 3D cubes:
https://tools.altiusinstitute.org/cubemaker/
One can color sets of points by putting labels and category names into fourth and subsequent columns. One can also click and drag to rotate and zoom, and export to PNG or PDF with selected view and metadata customizations.
No, this renders generic 3D datasets. Do your PCA, PCoA etc. and generate your result matrix. Import it into this tool to generate a figure.
Log in to answer this question.
