2
votes

I'm getting the following error message for trying to do a (basic) plot of a PCA using ggplot2:

Error in plot_label(p = p, data = plot.data, label = label, label.label = label.label, : Unsupported class: princomp

The plot works in R's own biplot function biplot(prin_comp) so I'm not sure if I've got something wrong in how I'm asking ggplot to do this or if it is a problem with the PCA output that makes it unsuitable for ggplot. I can't post data (confidentiality issues) but it is quite a big data set and I could post the PCA output if that would help?

EDIT: Here is an example using mtcars dataset, which has same results:

library("ggbiplot")
data(mtcars)
View(mtcars)
pca <- princomp(mtcars, scale=1)
princomp(x = mtcars, scale = 1)

Standard deviations:
     Comp.1      Comp.2      Comp.3      Comp.4      Comp.5      Comp.6 
134.3827868  37.5472829   3.0226511   1.2860724   0.8922099   0.6530910 
     Comp.7      Comp.8      Comp.9     Comp.10     Comp.11 
  0.3037193   0.2814568   0.2467490   0.2073344   0.1952988 

 11  variables and  32 observations.


ggbiplot(pca)

Error in plot_label(p = p, data = plot.data, label = label, label.label = label.label, : Unsupported class: princomp

Again, that works in base R's biplot function. I am looking to get the following kind of output (not the plot shown in answer below), hence using biplot rather than autoplot, apologies if this was not obvious: biplot mtcars

Can't find similar error on googling or search on here but happy to be linked to if anyone else can find it.

Please see here on making a reproducible R question folks can help with. That includes a representative sample of data—doesn't have to be your actual data, can instead be a commonly available dataset or random data that simulates the issue—and all necessary code neededcamille
Have edited to add an example with mtcars dataset. Thanks.Zurgle