combine_vars(vars,ind_list)出错:使用ggfortify和cluster可视化PCA结果

时间:2017-06-07 02:44:34

标签: r pca ggfortify

我正在尝试按照此处https://cran.r-project.org/web/packages/ggfortify/vignettes/plot_pca.html的指示使用ggfortify可视化一些PCA结果。

这是我的数据集:

sample1 <- structure(list(labels = c(rep("Condition1",3),rep("Condition2",3),rep("Condition3",3),
                      rep("Condition4",3),rep("Condition5",3),rep("Condition6",3),
                      rep("Condition7",3),rep("Condition8",3),rep("Condition9",3),
                      rep("Condition10",3)), 
           species1 = c(0.8854078,1.1426745,1.1997603,1.0752697,1.9146937,1.9551159,
                        0.9922772,1.8622131,1.9098490,1.0333174,0.8282050,0.8441316,
                        0.7967572,0.8551591,0.9468684,0.8860703,0.7994813,0.8080075,
                        1.2594811,1.1314699,1.0391089,1.0937708,1.0020137,0.9798906,
                        1.1896010,0.9886625,0.9184887,0.7433927,0.9162975,0.9110867), 
           species2 = c(0.8901513,1.0258955,1.1474593,1.0235203,1.3896777,1.5973619,
                        1.1878031,1.6099871,1.7580490,1.1427220,0.7071613,0.7560707,
                        0.7514282,0.7191674,0.8902374,1.3310765,0.6761733,0.7420234,
                        1.0251943,1.1350485,0.8723263,1.2321523,0.8916545,0.8315078,
                        0.8729525,1.0623186,0.8274900,0.9045540,0.7310989,0.7677916), 
           species3 = c(0.9662067,1.2001695,1.3431823,1.0595119,1.3833918,1.7351321,
                        0.6916019,1.1917492,1.5819428,1.0543243,0.9598088,0.9540960,
                        0.9418114,1.1564554,1.2758472,1.1501074,0.9732534,0.9465542,
                        1.0501864,0.9820822,0.7656833,0.9566891,0.7713283,0.7583800,
                        1.0911549,0.9461998,0.7428917,1.0001292,0.9719712,0.9313093),
           species4 = c(0.7683807,1.4180243,1.4913914,1.3634394,1.6938784,2.0093107,
                        0.9411017,2.2384420,2.3109009,1.1387285,0.9596912,0.9513277,
                        0.6880320,1.1848339,1.3143804,1.4067813,0.8328677,0.8561612,
                        0.8263480,1.0818343,0.7703761,0.9124809,0.6062723,0.6545570,
                        1.1832932,1.0339432,0.7443652,1.1154476,0.8497842,0.8511975), 
           species5 = c(0.9572177,1.3932815,1.4020281,1.1314849,1.6915749,1.7423292,
                        1.1445479,1.4396891,1.5233912,0.9904151,0.9439300,0.9472164,
                        1.0387161,0.9559629,1.0126704,1.1433313,0.9523364,0.9439938,
                        1.2334351,1.0288614,0.9527279,0.9237914,0.6949624,0.7079906,
                        1.5397641,0.8460837,0.7982519,0.9132740,0.8411369,0.8439991),
           species6 = c(1.0439714,0.9893081,1.0110028,0.9781595,1.0104842,1.0536184,
                        0.9939584,0.8124520,0.8565823,1.0299807,0.9819601,0.9848036,
                        1.0614300,1.0318185,1.0549166,0.9659700,0.9615660,0.9546094,
                        0.9888312,1.0165082,0.9852863,0.9685218,0.9886145,0.9875676,
                        1.0036011,1.0101036,0.9799294,1.0237522,0.9902889,0.9855792),
           species7 = c(0.9328656,1.2854305,1.2898100,1.0467648,1.3192825,1.3513350,
                        0.7220414,1.1949623,1.2363336,1.1368031,0.9352001,0.9396318,
                        0.9466253,1.0874090,1.1093370,1.0653638,0.9490317,0.9428856,
                        1.0399305,0.9240539,0.9036315,0.9486899,0.7473155,0.7584183,
                        1.1038823,0.9570963,0.9351377,0.9462613,0.9032550,0.9029622),
           species8 = c(0.9604464,1.2623905,1.2728665,1.0226677,1.3284123,1.3723773,
                        0.7151207,1.2286889,1.2838473,1.1727388,0.9447701,0.9486432,
                        0.9946795,1.1421753,1.1651877,1.1121437,0.9121262,0.9078907,
                        1.0222506,0.9264043,0.8983589,0.9461709,0.7986562,0.8063740,
                        1.0669461,0.9087593,0.8825160,0.9909126,0.9382247,0.9353111),
           species9 = c(1.1268171,1.7182203,1.6682739,1.3667400,1.4472609,1.7220027,
                        0.8512170,1.5833162,1.8001507,1.5587438,1.0149041,0.9957001,
                        0.9458149,1.1636174,1.2586902,1.5092807,0.9218130,0.9146309,
                        0.9146585,0.7764501,0.6896659,0.9008603,0.8169017,0.7983043,
                        1.3871795,0.9755146,0.8183833,1.0444352,0.8010848,0.8139960),
           species10 = c(0.9632305,1.2843560,1.2843606,1.0453979,1.4559130,1.4700216,
                         0.7202460,1.2099570,1.2369601,1.1035078,1.0026660,1.0051063,
                         0.9473880,1.1149870,1.1305114,1.0628961,0.9140461,0.9098227,
                         1.0242460,0.8829375,0.8721637,0.9532801,0.8127208,0.8228729,
                         1.1044777,0.9628386,0.9491688,0.9659567,0.9734319,0.9714403),
           species11 = c(0.9216739,1.2844749,1.3348376,0.9948908,1.3635805,1.5213323,
                         0.6891492,1.1190134,1.3050141,1.0902293,0.9565687,0.9569387,
                         0.9892187,1.1349498,1.2010546,1.1020109,0.9419127,0.9320829,
                         1.0274009,0.8933980,0.8079352,0.8902054,0.7705972,0.7713996,
                         1.0949460,0.8986867,0.8107097,0.9517565,1.0002236,0.9768961)), 
      .Names = c("labels", "16:1/22:0","16:1/23:2","16:1/25:0","18:0/15:2",
                 "18:0/17:2","18:1/16:2","18:2/18:1","18:2/24:0","19:0/16:1",
                 "20:1/24:0","20:1/26:0"), 
      row.names = c(NA, 30L), class = "data.frame")

我可以使用以下代码使用autoplot()lfda()绘制结果:

library(ggfortify)
library(lfda)

autoplot(prcomp(sample1[,-1]), center = TRUE, scale. = TRUE)

model <- lfda(sample1[,-1], sample1[,1], knn=2, r = 2, metric="plain")
autoplot(model, data = sample1, frame = TRUE, frame.colour = 'labels')

但是在使用cluster库时遇到以下错误消息:

library(cluster)
autoplot(pam(sample1[,-1],3), frame = TRUE, frame.type = 'norm')

错误消息是:

 Error in combine_vars(vars, ind_list) :
   Each argument must yield either positive or negative integers
        In addition: Warning messages:
        1: In 14:0/16:1 :
         longer object length is not a multiple of shorter object length
        2: In 14:0/18:1 :
         longer object length is not a multiple of shorter object length
        3: In 14:0/20:3 :
         longer object length is not a multiple of shorter object length
        ...

cluster包与我的其他数据集一起工作,所以我猜这个特定的数据集本身可能有些东西(比如不吉利的数值)......?我一直无法弄清楚这些消息是什么意思或者如何自己解决这些问题......任何帮助都会非常感激!

非常感谢!

0 个答案:

没有答案