【问题标题】:ggplot error: 'names' attribute [2] must be the same length as the vector [1]ggplot 错误:“名称”属性 [2] 必须与向量 [1] 的长度相同
【发布时间】:2019-07-17 14:27:37
【问题描述】:

我想使用 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]

【问题讨论】:

  • 请记住,我们既没有您的数据也没有您的输出,因此我们无法运行您的代码,也看不到发生了什么。使用reproducible example 提供帮助会更容易

标签: r ggplot2 pca


【解决方案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

此代码是由与我一起工作的人传给我的,但我没有遇到任何问题。

【讨论】:

    猜你喜欢
    • 2021-10-06
    • 2018-01-20
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 2013-09-22
    • 2016-08-30
    • 1970-01-01
    • 2020-01-04
    相关资源
    最近更新 更多