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 



 


  

 
Here's a [tutorial I wrote][1] using the rgl package mentioned by Jean. It includes 3D labels, exporting and animating. Hope it helps!


  [1]: http://www.2-bitbio.com/2017/04/animated-3d-pca-plots-in-r.html