2
votes

I'm trying to carry out a PCA Analysis on my dataset, and I can plot the loadings out on the basic plot function. But I want to do them on ggplot, but I keep getting this error, "ggplot2 doesn't know how to deal with data of class loadings".

I'm using the princomp function, and I'm plotting my first component against my second component. And I need to colour it on the basis of an external factor which has the same rownames as the dataframe I'm carrying out the pca on. I've tried to do the same thing as this Tutorial with prcomp, but with pca$loadings, but it didnt work. I need to plot my first PC against my second PC in ggplot.

Blockquote

xy <- princomp(iris[,-5])
plot(xy$loadings[,"Comp.1"], xy$loadings[,"Comp.2"], col=iris$Species)
ggplot(xy, aes(x=xy$loadings[,1], y=xy$loadings[,2]))+geom_point()
1
You are brilliant! Thanks a ton! It worked!Ar1229

1 Answers

1
votes

ggplot(as.data.frame(xy$loadings[,1:2]), aes(x=Comp.1, y=Comp.2))+geom_point()