#' parallelplot function
#'
#' This function creates a nice plot of your PCA results against the Longman and Allen results.
#' @param comp Your results from `princomp()`.
#'@keywords parallelplot
#'@export
parallelplot=function(comp){
if (comp$n.obs>1000 || length(comp$sdev)>100) {
print ("Sorry, this only works for n<1000 and p<100")
stop()
}
parallelanal <- parallel(comp$n.obs,length(comp$sdev))
calclim <- min(10,length(comp$sdev))
eigenvalues <- (comp$sdev^2)[1:calclim]
limits <- as.matrix(parallelanal[,2:3])
limits <- limits[complete.cases(limits)]
ymax <- range(c(eigenvalues),limits)
plot(parallelanal$pcompnum,eigenvalues,xlab="Principal Component Number",ylim=c(ymax),ylab="Eigenvalues and Thresholds",
main="Scree Plot with Parallel Analysis Limits",type="b",pch=15,lwd=2, col="red")
#lines(parallelanal$pcompnum,parallelanal[,2], type="b",col="red",pch=16,lwd=2)
lines(parallelanal$pcompnum,parallelanal[,2], type="b",col="green",pch=17,lwd=2)
lines(parallelanal$pcompnum,parallelanal[,3], type="b",col="blue",pch=18,lwd=2)
#legend((calclim/2),ymax[2],legend=c("Eigenvalues","Stick Method","Longman Method","Allen Method"), pch=c(15:18), col=c("black","red","green","blue"),lwd=2)
legend((calclim/2),ymax[2],legend=c("Eigenvalues","Longman Method","Allen Method"), pch=c(16:18), col=c("red","green","blue"),lwd=2)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.