ggplot错误:“名称”属性[2]的长度必须与向量[1]

时间:2019-07-17 14:27:37

标签: r ggplot2 pca

我想使用PCA,但无法绘制!我使用packege和以下代码成功运行了PCA:

  pc<-prcomp(C, scale = FALSE)
  summary(pc) 

然后我使用的情节

   library(devtools)
   install_github("vqv/ggbiplot")
   library(ggbiplot)
   ggbiplot(pc)

但是我得到这个错误:

   Error in names(df.v) <- names(df.u) : 
   'names' attribute [2] must be the same length as the vector [1]

1 个答案:

答案 0 :(得分:-1)

我通常使用ggplot满足我的PCA绘图需求,因为它允许我通过颜色/形状编码覆盖元数据。

我用于基本PCA的典型代码是:

    library(ggfortify)
    library(ggrepel)
    library(GGally)
    library(gplots)
    library(ggplot2)
    x <- prcomp(y)
    autoplot(x) + #any color/shape/text edits you want to make

此代码是由我与之合作的人传给我的,但是我没有任何问题。