Starting dataset


Let’s start generating 3000 random datapoints normally distributed on only two dimensions (corresponding to two variables X1 and X2)


X1 = rnorm(1000, mean = 10, sd= 4)
X2 = rnorm(1000, mean = 0, sd=2)+(X1)
X3 = rnorm(1000, mean=10, sd=1)


df = data.frame(X1,X2,X3,row.names = c(1:1000))

kable(df)  %>% kable_styling('striped',fixed_thead = T, full_width = FALSE) %>%
  scroll_box( height = "400px")
X1 X2 X3
1.4909588 -0.6389581 10.709623
8.8661404 8.7073640 11.471004
12.8810614 13.9365537 10.230943
10.8436140 10.4047321 9.134547
9.3043068 7.1836192 9.685626
7.7831814 6.9816489 10.534997
5.9432539 5.6614064 9.548322
4.9467533 6.9337704 10.902752
6.9220214 6.2107450 9.832676
10.0966817 9.3955005 9.228428
12.4121890 14.1294338 10.459287
11.2689822 5.0779426 10.395555
9.4643349 11.7299677 9.100904
7.0386780 9.6461749 11.586456
11.5538911 12.3370426 9.795076
7.3112210 10.5857706 10.961347
5.1261357 6.9426609 9.593046
6.8497627 8.8087887 11.433069
12.4774752 9.7037982 11.447245
10.9943912 10.4998876 7.901226
4.4965188 6.2414803 7.924243
8.9918887 8.3513003 10.872180
3.3979956 5.2446425 10.448392
7.1527506 7.6706340 9.897177
14.1351298 12.3260921 9.753251
4.9257138 4.9702961 10.902371
9.8736833 10.6587654 9.534753
6.0530397 4.8881948 9.313907
8.4598991 5.1527676 10.094032
10.9090450 12.2330325 10.046435
6.2581585 8.7584469 8.264087
6.4994857 6.4202630 8.492995
10.0170744 11.8054749 10.059009
11.4093763 14.2107900 8.638742
11.6994672 10.8767603 10.323034
10.4783430 13.0698156 8.991778
7.0820853 8.1625625 10.324515
16.5773473 13.4558469 10.618150
5.9651965 3.8706449 12.286403
10.8336376 12.1097501 11.698716
3.5466281 4.3594412 9.074896
10.9875047 12.7873971 8.557177
4.8694575 5.5827304 9.494495
12.1088881 12.4950181 10.430490
5.4460932 4.4460587 11.124682
12.6399700 8.6359556 10.931346
10.6266983 10.1012932 8.969173
14.0036475 11.8254686 9.443371
10.3046093 9.5407052 8.283380
3.1448992 1.6492712 9.966247
13.9960147 15.0436850 9.558890
14.0059720 14.2783639 10.294165
7.5234001 7.1477796 11.178862
8.8869599 11.5652081 11.188987
5.3467236 3.5777234 10.997024
8.7482258 6.8120298 9.574035
20.0308595 20.7585669 9.649527
7.6233408 8.9479791 11.181825
16.5969767 15.2837727 9.325711
6.5026075 2.8191043 11.673504
6.3223045 7.8028827 10.024004
7.2293570 5.1479968 8.798702
6.7188751 7.9843427 8.550795
15.9219684 17.0831428 8.891647
13.0538399 14.2979386 11.247331
2.4050958 -0.4557150 9.142496
21.0122571 21.9707826 10.191486
15.3259107 14.9541510 10.780581
12.0080748 9.3653300 9.400608
9.4182007 8.4712807 7.802521
8.8539972 6.0909222 10.498696
9.2389550 9.9140137 10.637811
8.3020347 6.8674215 9.464821
11.5014216 12.8381791 10.894521
4.5452927 3.5506048 10.616071
5.2134867 4.6052357 11.259886
10.0111845 10.4340597 10.201728
11.8338853 9.3582959 9.901110
8.0586383 7.3173203 10.400552
11.3506444 11.6774648 9.489989
14.1084819 11.7230324 11.683733
11.2328742 8.9207590 9.780919
4.7061705 5.9708429 11.263618
2.6301488 0.7224523 9.862005
16.5962359 14.6412097 10.160043
6.3489102 6.6656994 11.173606
11.7250973 16.1332336 10.329215
12.7088167 13.1810042 9.688160
3.2865816 4.4935483 9.063980
9.9365339 10.4496779 11.439412
9.8318150 8.8957332 12.059693
5.3576888 3.7747028 9.979358
10.2844123 10.5753169 11.202658
17.6358096 17.9537155 9.327340
4.4576912 6.3941086 10.551267
6.5038644 2.1277925 10.366587
12.4544011 10.3089511 11.384161
2.4820515 1.5670534 10.338174
12.5702740 10.4874465 9.735121
13.7963063 11.3761341 10.372152
2.5378127 1.8939610 10.896983
10.4261673 10.5488772 9.149140
15.0067867 14.7077756 8.944410
12.9340796 14.9261367 10.486089
13.6311816 10.3414719 11.948300
10.7158885 9.6252148 10.378235
5.9417729 7.8296579 10.618738
9.8726225 11.0361835 10.291287
12.7819617 14.7604046 8.124759
16.2812170 15.1102968 10.529285
13.1698850 16.9927275 9.173697
12.6480701 11.1893071 11.426168
7.6525087 7.8726254 9.413732
10.5413378 12.2544557 9.464386
11.7023837 10.8324938 9.322382
7.3165911 5.2229696 10.944692
8.9879119 7.4639354 9.523481
6.4819762 7.9459722 10.001118
10.7661187 13.0074908 9.895431
9.3386948 8.9099625 9.804283
11.7414185 11.0650301 10.456464
11.0225344 12.4816370 10.056040
13.5548612 12.8439916 12.886254
12.5593890 14.9199990 9.499501
10.4420280 10.0675517 8.602741
10.4072273 8.4694782 10.267263
8.2949404 8.4800364 10.527556
6.8263458 8.7768736 11.935713
7.0673012 4.6355924 9.642320
14.5597353 15.7830026 9.035205
13.3678756 13.1185655 8.500535
13.5968520 13.4477081 9.859218
13.5791810 15.1602622 8.183574
15.1131045 12.5315531 10.327759
8.0699674 9.5698615 11.263011
15.5654468 12.6361911 9.668805
10.6585288 9.5913091 10.321656
-1.7623321 -2.6885333 10.644788
6.6256828 6.6346638 8.943923
16.4577011 18.5111446 10.228546
7.2615853 6.3607463 11.360006
11.8344016 10.2697098 10.343649
9.2685793 12.5521327 10.101639
12.9913444 14.0470024 8.420625
13.6544885 13.9611619 9.722917
10.1000842 12.8595163 8.758705
6.7970089 5.5964919 9.762397
12.1246336 15.1714444 9.012775
11.1275522 11.1767525 11.208538
9.7055173 9.3426581 9.824741
8.8605399 9.8232996 10.949301
12.2457325 12.5387897 8.690040
11.1844895 10.6940730 10.694741
6.5973983 4.6187643 10.218819
8.2842140 10.1601260 9.297192
14.2366549 14.9039233 10.223940
7.3547605 10.9435669 9.421317
14.2569717 15.2011335 10.501986
6.8963229 5.0632032 11.619684
5.8955844 4.7472728 8.202959
11.2954381 12.4799114 9.851451
9.8559129 9.0513027 10.857762
9.5701946 8.5290857 10.458161
4.9963424 4.9703352 9.215633
11.3236917 15.4031462 8.320276
10.6123034 12.9368071 10.377056
0.1854947 -2.4343085 9.990988
16.4187796 16.8815238 10.192109
11.0892414 8.5276548 10.215945
7.7017689 5.4540864 8.276279
13.1817135 16.9491096 10.454233
12.5966882 11.8824754 9.995958
4.9556644 3.4791608 9.915157
10.7866145 13.2826106 9.488736
9.1729844 10.7706718 10.042710
10.9721223 10.6800096 9.690614
9.7222145 10.4013347 9.245404
9.0730359 9.5853178 9.207158
11.2511586 13.5697558 8.395999
11.4092026 11.9132083 11.339951
8.4244610 7.2027173 10.330524
18.2339749 20.8640154 10.899649
12.2595600 8.8948648 11.900167
12.6258066 18.7156319 9.782942
10.0295910 11.5950886 9.476076
15.4093993 14.5973649 11.824482
8.0870112 11.3395974 9.950527
8.4601872 8.8085177 9.919723
2.6416853 3.2850831 10.801697
3.2831628 2.8528549 11.590493
7.9189650 10.3065768 12.294019
7.8938442 9.6345388 9.576934
11.4693911 13.8729497 10.105551
0.8085023 3.9114011 10.200695
9.9768068 12.4765841 9.705118
0.3085731 0.2969684 9.287101
12.9178805 14.5372039 8.192500
13.2069053 9.6456828 8.572788
9.7399495 12.8862305 12.466873
13.4628285 11.1574667 9.692570
5.2828637 4.6840917 9.236272
14.5609259 11.3769924 9.898125
11.8260500 12.1553196 10.445208
5.3535655 6.1804934 9.737553
8.1293321 9.8190953 11.072710
13.1230567 11.2567747 8.874631
11.9256471 9.9474865 11.134224
4.3935609 2.8045371 9.551009
13.9456545 14.6782531 8.241109
12.0952942 12.8867354 8.971018
8.7810405 10.1403737 11.460629
7.7005010 8.7188233 9.835289
6.5979039 6.2458473 9.708072
8.1711484 10.6385544 10.383178
14.7762449 17.1101180 10.767952
7.5643191 3.9865081 12.000453
9.6689115 9.8836355 9.512696
7.7844008 7.3445180 10.726642
10.2130084 11.0846823 8.503927
13.7941021 14.0264297 9.444221
6.8384716 7.2292029 11.865453
12.7325645 12.5406209 8.530679
17.4025693 15.1903116 10.397487
1.2946229 2.8099226 10.326512
10.0009617 14.0555087 10.531557
19.9286933 19.8734435 10.947919
11.9545532 9.2160180 9.719627
6.3394771 2.1131538 8.914133
12.8073326 12.4685143 9.687574
11.5282558 13.1362970 10.550027
9.8675326 8.1083441 7.747620
10.2766291 11.3762311 9.059866
12.5562877 12.6791600 10.695300
15.1719131 16.4641763 7.789139
14.9580789 16.2278999 10.135527
12.3720171 14.4301733 11.723879
14.6403840 14.5581490 7.574319
5.1895017 2.2783536 8.687378
11.5970394 10.4846804 9.129014
9.4807550 10.9758987 10.368493
10.0818765 12.0423007 9.965605
5.7537586 8.0543660 10.410221
8.4866732 8.2523409 10.615868
6.3709784 6.9684358 10.982509
10.7889274 12.4358750 8.713812
5.0630675 6.2063873 10.251944
10.7137423 13.6868886 9.997985
15.9410372 17.7501818 9.986724
7.8161134 7.5564794 10.162106
8.8381324 7.2981224 11.580652
8.4990172 6.8662854 9.756463
8.5823784 13.3774871 11.372020
8.4878185 9.5060824 10.779898
8.5626441 8.7062717 9.038320
8.0450959 9.1041841 10.298579
11.7780150 12.7569069 8.191127
2.2494483 5.8489281 11.776350
9.9003875 11.3421366 10.030533
8.5025373 5.5620334 10.411976
7.2024426 7.8172858 10.432225
14.7852983 15.2080015 8.246940
9.1955790 5.6602506 9.649601
14.7178051 14.1299545 9.194136
14.4455234 14.9265762 9.146901
9.1829883 7.4320508 10.435381
6.4781968 6.6775380 9.357885
8.9800930 5.6895690 9.661573
6.3216736 4.4188718 9.206619
1.3976719 2.7535171 9.012864
8.9680626 9.5962201 10.875255
11.1935545 12.4938880 10.257062
14.4127318 16.1755010 9.815529
12.6654139 12.4544808 9.620384
9.9720800 8.7054804 9.591905
12.7510585 9.1212718 12.247961
14.0991803 16.8484847 9.974698
9.9028728 12.2206389 10.403971
10.1996181 8.4917620 10.357818
9.9203603 10.3338728 12.303684
13.5586467 14.7056227 9.128771
14.7231170 14.7502141 9.111765
5.7739550 9.1119584 10.157638
4.7065563 4.3814860 10.808025
7.3163130 8.6416065 10.144435
14.0462965 13.0337968 8.665644
14.8913041 17.2163456 9.869654
5.7815287 5.6640317 11.484240
8.5076194 5.0386328 10.110891
17.8249134 15.5924434 8.865232
11.2355553 12.3202705 10.607450
2.3296314 1.7359762 12.110265
15.0895733 15.1502108 11.644574
10.3769009 12.3285001 9.075187
17.6077824 18.7252516 9.540314
10.8046739 10.7162424 9.675367
3.9969171 3.2915792 10.177407
12.4805690 12.2953485 9.185658
8.7937238 9.6133852 10.779702
3.1725327 1.2038426 10.920082
7.0122328 8.0376016 10.225442
11.6452210 9.6016604 10.384878
8.7959630 11.0551107 9.348979
6.1664505 5.8040434 11.839659
12.6169968 10.8821370 10.854780
6.1469767 5.9204724 10.307662
16.8747266 17.9829690 10.406625
13.0564072 12.1983541 9.993719
11.7102068 9.1151820 8.582378
12.5902543 12.3257706 10.039596
11.1780205 8.1459869 9.682916
8.2872343 7.3171051 8.501763
11.1240363 12.2193122 10.306861
6.8775600 6.9591520 9.578339
13.9332123 11.8323760 9.120768
3.3314235 1.6711157 10.011087
17.5834818 16.9725293 10.011633
10.0115978 8.8147448 9.598892
9.2917059 6.6469303 9.909386
4.6115207 1.8090884 10.694811
-2.9264863 0.6728550 10.858056
12.7580745 12.0626759 9.428239
12.5729447 12.5655701 9.595496
5.4047812 8.8741360 11.067021
8.4826386 11.3767256 8.776779
7.8409668 6.1243952 11.500371
7.2323805 7.7031171 9.563275
6.3539028 7.9391895 8.595427
11.8727890 10.6035395 10.201974
7.1845153 7.0112698 9.562410
7.9285714 9.7785169 10.504202
11.2493335 11.3372270 9.561984
9.9874005 9.5507564 9.428083
13.1646745 12.5752892 10.549372
12.5282703 11.2988593 8.851055
7.5209958 9.1446738 9.914931
16.5325636 17.9159901 9.272659
9.9230198 9.6732827 10.086483
15.5167564 15.9806234 12.098173
10.8454231 10.7539537 9.910651
13.3609349 14.4750878 10.106438
4.8686300 7.1695349 9.183227
5.1981263 5.0528831 9.499130
17.0072423 18.7211063 8.887308
10.0173185 7.2743077 10.613763
6.0731280 5.3571618 11.845741
1.3724907 2.9522721 9.455200
12.7995730 13.8660168 9.119985
7.4944906 8.5176280 9.181150
5.2620616 5.8083663 8.979508
11.7879006 11.2503164 10.144148
11.5641651 16.3782257 9.255743
14.1828897 15.2902096 11.729578
6.3705197 7.3245531 10.375376
11.4873093 9.6368661 11.422506
14.0494779 12.8203135 9.289360
10.6037045 9.6027391 8.834974
7.2335496 2.9340784 6.857445
3.5354565 0.2442785 10.237863
8.6074760 9.5347559 10.967982
8.8138879 8.0032375 10.123572
3.8530878 3.7341892 11.769426
13.9268255 13.8206090 7.456638
12.9287883 12.4149589 10.959235
15.3888167 15.8623315 10.750744
8.0470718 9.6597781 9.507318
9.6016789 13.3277378 8.314076
6.5547550 7.1065502 11.547911
16.3369591 19.2800507 9.973123
14.3676842 16.3082762 9.886447
8.0391921 6.2309962 9.305704
10.4061073 10.6205888 9.318768
9.3509098 8.6716802 12.455845
4.2677384 5.6855050 9.427536
5.7867074 8.0771220 10.207116
16.3404414 14.0945225 9.344262
18.1259525 16.8037281 10.915700
9.7308076 5.9339257 12.156376
3.2771086 3.7023046 11.447219
14.8630298 16.6878353 9.642906
19.5118591 17.7183275 11.969430
1.5286825 0.4102832 9.067825
10.5911938 9.9156709 8.255581
12.6183008 14.7537696 9.163429
11.4206239 9.7835261 9.201572
15.9564136 12.7564407 9.440954
8.4072554 4.8940080 8.862370
16.6060400 16.5010767 10.569273
11.2428629 11.0746208 11.153761
10.4838057 11.6114824 11.140848
5.9520057 5.6115120 10.057621
12.4604024 11.6136474 10.016933
5.4602091 3.1574651 10.228950
9.8216121 9.5085669 8.957423
8.2091080 10.2567281 9.608897
11.3436768 8.8590613 11.125772
7.9214462 5.4767545 10.701387
11.9909710 10.7464616 8.966577
13.9933130 12.0850625 8.878817
7.3213722 8.0925016 9.771880
9.3614268 9.0959317 10.929376
5.0647628 7.9310951 9.703585
8.3063392 7.3119631 9.611049
10.7084072 9.7870336 9.777873
10.3932704 7.5709582 9.106032
5.5136333 5.9192315 10.003073
5.2181726 3.6879819 11.527813
11.3855968 13.2069677 10.484561
12.8818658 11.5969697 8.810835
10.3928456 11.4484758 10.963827
14.1361725 14.5115058 10.334878
7.0293344 6.2957795 11.527066
8.3738456 9.7900231 9.210700
3.0794275 3.8455750 11.698528
8.9037923 9.9428110 10.129973
9.4216478 8.7615355 8.535801
4.5298293 3.1194673 9.684449
6.6845007 7.3301144 10.504980
9.8543423 9.7871248 9.508397
13.7405319 11.1827358 9.896803
13.6151072 14.1411871 10.564578
7.5773697 9.7551868 9.523077
14.9378410 16.9406503 8.828520
12.4805825 12.8016492 10.603405
9.1121528 9.7643436 9.612765
7.0660231 9.6610732 9.908298
8.7006530 9.3053378 9.322445
11.7138662 11.7088805 9.011800
11.4330197 11.7370351 7.938000
10.1183403 10.5528153 10.069685
15.2275900 14.5448767 11.029003
13.5160217 10.1701531 10.317861
7.6224997 6.8102443 9.021301
11.6281142 12.9435895 9.772408
11.0856057 10.1234794 8.573417
11.7365220 12.5720986 9.952327
4.8120286 5.7664922 10.396878
14.8295934 15.2347417 9.632205
9.6942207 12.4584050 10.221941
10.3910310 10.5765957 9.865824
5.4375446 4.9474808 12.465346
15.0056124 12.8817388 9.858408
14.6460361 15.5888525 11.890997
9.2422320 7.3157614 9.374597
9.5746904 9.2969703 10.503386
10.0286504 7.0699152 9.722644
13.0126865 14.6897440 9.148162
13.3431004 14.3644744 10.183553
18.1583183 16.7296558 9.132059
7.5289871 8.2693828 9.820781
11.1632339 14.6705248 8.036066
12.7452491 12.9101322 10.834834
3.8656109 4.9183552 10.895645
7.9031401 6.1436692 11.949807
16.5979389 17.1271733 10.279290
9.2465557 9.3228939 9.741906
11.3162361 12.7048530 9.007874
10.3471846 13.4874662 10.606642
10.5750818 12.3599574 9.767329
7.8908811 8.9362046 11.420670
8.2103465 10.9157146 10.251212
4.3558573 3.1723915 9.083797
17.0165125 16.2326402 9.220187
17.0618217 17.0673764 9.008228
8.1459735 5.9045689 8.690499
19.3256000 20.6624167 9.176115
16.6835403 18.9005619 9.895711
0.9675794 -1.0407440 9.669160
11.3328730 12.3771510 8.312394
14.8547359 13.5173788 8.818014
8.6098282 11.0828863 8.617932
9.6566643 8.6524688 9.235712
13.8626599 13.6336936 9.632229
7.2644851 7.9764259 11.106981
9.6695350 13.5818482 9.308055
12.1243997 13.8106055 9.411216
11.5985183 14.6180481 9.977975
10.8276696 11.9828803 11.324249
5.1595715 4.4817402 8.988899
6.4878922 5.9848498 9.552347
9.2660367 10.9425968 9.591490
15.2157591 19.0791948 12.067307
16.3372630 16.1744515 9.218720
10.1191227 12.7070120 10.040299
11.1225011 11.4060465 10.256264
13.3577367 17.5107993 11.077966
9.9188290 13.4980326 10.371727
7.4433242 9.0308196 12.926746
7.5176980 7.8761269 10.111553
12.4357043 11.8310221 10.897562
10.4780077 12.0744181 10.299336
12.5756855 10.6684254 10.143678
7.8139426 2.8123347 10.209686
12.7435749 13.3532957 7.970736
8.4687074 7.8122913 10.557721
11.0359040 12.0825764 9.485476
9.8420464 5.0416252 10.220693
3.6930708 -0.2394072 7.967416
7.1297894 5.6024828 10.088557
6.3592121 8.7754980 10.120866
9.7443131 10.8380537 10.274751
13.6376131 11.0875668 9.867968
4.9652816 4.2333561 10.399828
9.6234801 8.2173189 8.860615
13.5670567 12.1855711 10.828229
8.1140084 7.9030517 8.391306
8.6195600 11.4507255 10.110521
4.6169007 5.5256782 10.724655
11.2981838 12.0376167 9.935078
12.3573563 15.4806057 12.001539
7.6811959 3.1856118 9.641675
9.7288846 11.0848948 9.508001
13.8299590 12.3025901 11.138382
11.2780660 8.1641107 9.041701
4.5111512 -0.7847685 9.055219
8.2324550 8.5790011 8.886452
4.2420511 1.6554450 11.143887
18.4541131 20.3616825 8.755100
5.7814657 6.9178607 9.993405
6.5054877 9.3641638 10.551417
7.4768443 9.0843409 10.223067
9.5686605 8.2505906 9.389559
16.7730836 15.2345359 10.302773
10.1384849 8.3364911 11.234580
9.5374157 7.2120194 10.031883
8.6098738 8.6478803 9.920670
15.0878710 17.0282135 9.364089
3.1045440 1.6999714 9.600704
13.1614721 14.3319027 8.449530
11.9866391 16.0230871 9.874506
11.9618980 14.4151721 10.124788
7.3653389 3.7294576 9.205371
11.6746380 6.4771500 10.385229
7.6596400 7.7632604 10.531323
4.3143030 9.2668677 10.994500
14.5035136 15.1020301 10.104057
11.4146424 7.4102002 11.952200
9.1056038 14.0466906 10.268225
8.7966803 5.1207106 7.749341
10.2094281 9.9170912 11.270072
6.5996552 5.0637256 10.493248
7.9520110 8.6691477 10.575724
9.9180294 8.2558096 8.482893
12.4423239 13.0565601 9.023594
4.4353559 5.6819182 12.184934
12.9704169 14.3380035 10.121481
5.1989221 2.5038696 9.567028
11.7316123 13.1059153 12.708795
2.1894377 1.7044993 9.961818
7.7460702 9.7590827 11.066108
9.0658520 6.8798681 10.060122
4.3277263 7.5336307 9.968665
6.4414175 5.7191351 11.725462
12.1039115 11.0420339 11.887432
11.5304417 8.3334863 10.473566
5.1607329 1.3459986 9.372957
9.6308419 10.1949427 7.425060
3.3539796 6.5803509 11.320369
10.5014729 10.1064373 11.213255
4.8043179 8.1117374 9.959665
17.1132544 19.2102572 10.973733
10.9164667 11.9347756 9.441087
3.8951958 3.2095531 9.125298
3.5854702 5.8869141 9.335212
9.8897899 7.3637152 9.071449
12.2670422 10.1436538 9.127694
4.5330434 5.4253580 10.600080
11.5479375 12.8004855 11.002012
5.3446865 9.1038377 10.275961
12.2588794 15.2296313 10.926321
11.1275413 12.7954605 9.714038
7.3754766 5.8871715 10.045565
6.5239573 7.2309785 10.445669
11.5154368 8.3078254 11.083604
3.4702926 5.8031580 10.121888
6.1354118 6.4932912 9.216973
7.6786847 7.5743666 10.052774
4.2036705 1.9051615 9.941319
14.2873511 16.7241232 9.649482
17.0100947 19.3657354 11.252327
8.6097820 5.0246231 9.850792
11.1089319 7.9312779 8.814936
7.2059466 4.3217963 11.205422
14.0353425 13.1900274 10.355386
6.8164037 7.0582551 9.250544
10.1618763 11.7449499 8.783730
10.3007655 10.8451264 10.542169
8.2629836 8.5066332 9.051784
7.0030472 6.8063018 9.794901
9.7956461 9.9417811 10.997299
8.0929015 7.5742351 10.500101
12.7788482 10.6433560 8.703264
10.2137039 5.3516904 8.230764
12.6220764 11.7913166 10.904279
5.0885480 5.3147042 10.073516
4.6732955 3.4984139 9.948080
9.4321981 11.3222967 10.480282
3.9961838 4.3386145 8.312383
4.8049074 8.4565815 8.612397
9.2266976 9.1488874 10.648434
6.7924111 7.1044197 9.006450
11.7316288 11.4433062 9.672605
9.8444344 8.7198378 10.025905
3.2323016 6.7714864 10.240023
10.6401025 9.9029990 11.738003
9.5967526 9.2977024 8.964505
6.7368918 8.5376816 9.756878
11.8040948 11.5864658 9.117885
11.8168634 11.5347929 11.416472
8.3210233 11.6714745 8.479842
11.7415225 13.2851357 9.054593
11.4138394 9.8058497 10.680251
17.1121498 17.6876925 11.255000
7.9189420 10.1231582 10.105469
13.0552520 16.5330757 10.058565
17.3340001 18.6747548 10.969364
10.9140311 9.9817215 8.560603
12.8474609 12.3763373 12.734923
10.8916176 9.0092545 10.615180
12.6701387 14.4322463 9.535456
5.4790989 4.3162912 9.023393
1.4049228 0.4902850 9.398555
8.7408541 9.5948150 8.663794
9.5945619 11.0273236 11.268860
5.0046959 3.8004722 7.829608
14.9270184 16.5325471 9.915528
2.8559839 5.7969312 9.592244
5.9081697 6.9451012 9.991188
11.8505353 10.2841017 11.084313
11.2312889 13.0656798 8.918682
16.6689218 14.8452671 9.154539
8.4392202 9.6063355 9.647034
11.6647908 12.1135341 9.711263
4.3408198 4.0496701 9.062157
7.3747881 9.3607032 9.425535
13.4663185 15.9180471 8.429809
9.9492265 6.0482718 10.984152
8.2997543 9.6307292 10.673925
10.8329326 13.3701328 11.697390
12.8660207 10.8972150 10.004004
4.2091295 0.7290111 10.169965
6.6111700 6.0561203 10.971188
14.7718704 15.1982753 11.224714
8.8769067 8.3449899 9.560958
14.3759753 11.4609267 9.728628
6.8145558 5.6844716 9.521164
12.7763252 14.6146221 9.138430
6.1453207 5.8428398 9.786125
14.2069199 12.5911988 10.192608
10.9279435 7.6478393 9.547566
6.9159711 8.4603940 9.435019
11.8436555 10.9711603 9.436410
4.2019170 4.3086145 12.090244
6.7325938 8.4596299 10.376541
8.1645698 7.2000672 10.977947
5.4486245 6.1037508 10.171266
11.3276771 11.1747945 9.843888
5.8006836 5.9591146 9.066661
11.3637500 11.4259796 10.633184
17.6601941 15.3635777 10.180700
8.2018543 7.3416218 9.762866
3.3101996 5.9402239 10.187970
4.3261274 1.9884129 11.702478
9.4191561 13.1283597 10.217256
4.5992096 5.7393613 11.279295
15.2392579 12.5241417 9.858362
5.6287172 5.9063315 9.161968
12.0691608 13.7417119 9.358653
12.8974583 12.6794679 9.550518
7.7799651 8.3559576 8.944121
6.6137793 5.0277868 9.376746
13.2723762 10.6030964 10.333618
8.5143267 12.4853671 10.219670
9.7561054 11.2323643 10.240687
7.6169428 6.1086858 10.234927
8.2849728 3.2281663 10.541214
5.7300272 5.3630818 10.984624
14.1629038 12.1587589 10.774774
9.8684576 14.3668296 9.271445
14.7246704 13.1612347 8.731097
10.4487100 10.0547411 9.249580
7.0066906 6.4987856 8.513232
9.2946079 12.7861762 9.727494
6.4700044 5.1446470 9.815604
14.3836790 13.4168687 10.010211
12.6841642 16.4961496 8.489889
10.6081242 10.1422229 8.769782
10.2880649 10.9534520 10.161100
3.7086017 4.7136970 10.328058
12.3770268 9.6261189 9.852677
17.3283522 15.7857120 9.114161
15.8971113 17.8584495 12.093745
10.2186963 10.3058758 11.382159
13.9219296 17.3904823 10.981800
2.1663558 -0.0220269 8.702988
12.4822718 7.6534713 10.635799
9.2338407 7.8256429 10.685476
9.6965597 11.3497646 9.788082
11.0010153 14.1409985 8.555241
13.2426161 12.7212937 10.775006
10.2125270 11.8299179 8.960548
8.4732473 7.8000750 12.671392
6.3622898 8.8580374 11.947259
2.6410986 -0.2614394 10.727650
10.6684070 10.6376439 10.018764
9.0120382 7.3228603 10.885425
4.8487167 8.0021196 11.879087
12.3775940 11.5305087 9.994118
17.6566014 17.5090203 9.885914
13.6133712 16.5275103 11.516482
12.1140771 11.9379428 10.443304
10.3941885 9.5671256 10.995979
11.7067120 9.7149302 9.841203
12.1576766 13.2922459 8.690045
9.6160220 5.2193938 12.219909
11.4653024 11.3176389 11.109099
4.5088080 5.6467272 10.763316
15.4593663 17.6695763 10.102850
14.5985750 15.9929515 9.380967
9.9224646 9.8787057 7.941949
9.9614322 7.9852858 9.677915
1.9858482 8.1655869 9.080084
8.7724658 9.2270203 10.092662
8.3699524 12.7649385 9.315528
14.3087232 13.1923942 8.095500
5.0497386 1.8792572 9.492756
9.3501552 6.7701566 9.598250
0.5350346 2.6356243 11.940637
4.1408982 3.1505799 10.540124
5.0821985 1.8880561 10.185638
17.8246593 15.7639332 11.844484
15.3736131 14.2519300 9.964136
10.8683398 12.3493342 11.508134
14.6856886 14.0438756 9.888895
6.4039347 6.0402886 10.668469
5.4270315 6.4760771 9.329402
6.9146644 7.9245542 9.473423
10.7273996 11.0367056 9.480907
7.0849809 5.9075391 11.154513
16.7983666 18.1625220 11.767593
14.2132940 12.7096017 9.706971
9.5572452 8.2813540 7.833005
11.6815455 8.2300557 10.086836
10.9261160 9.6607448 10.951147
6.4991126 8.1545395 10.368222
11.3453595 11.7448003 8.394049
8.4112638 8.7748591 9.657944
15.0269575 14.6200994 9.146785
6.3007057 5.5939181 10.689866
14.0253816 16.2506887 8.545091
16.6845201 11.7358598 10.197442
14.2910239 16.5973213 12.502343
13.2470910 15.9447160 9.897173
6.9891315 6.0496441 9.892985
8.6370833 12.9164714 10.772656
14.4557295 11.1870959 10.002415
7.7985805 5.6557922 9.032455
9.1017769 9.4556679 10.363475
9.8721506 11.6723860 9.282190
6.6780436 7.7099112 10.909337
6.8848939 5.4972960 8.280911
10.7466844 9.8262996 9.401369
18.8888509 21.2348658 9.391650
13.6796499 15.1680118 10.130928
7.7470560 8.9938982 11.186358
12.2085150 9.2364034 9.583692
14.9630400 12.6177238 7.115939
5.7928029 7.8867035 8.445230
12.0492380 10.4208627 10.825331
4.7898928 7.1706555 8.756444
13.3868668 14.3514512 10.575718
10.0516605 9.8486351 11.315914
6.9699959 6.9977244 10.772135
6.2914127 6.4686920 9.488776
9.6930972 9.4667924 10.215380
6.9751259 9.3509871 10.843787
11.3229729 10.7183807 9.721535
4.0176599 5.7130204 10.108986
7.0186268 3.6743038 10.199689
12.6238793 12.9666218 11.050416
15.6323921 17.3146996 10.805215
9.1364970 11.3506371 9.397455
3.9413670 2.2046862 10.005543
17.2191190 17.8472551 11.505797
20.3978717 18.7548019 10.593946
14.4221993 14.6912111 10.172908
5.6518306 2.9693986 9.761665
2.0094935 3.5187913 10.375002
10.0991824 10.3933702 10.278051
15.0263500 11.6512575 9.829766
7.6243036 7.9010932 10.371275
6.6458931 5.6943695 8.080281
13.5853365 12.1442941 10.689056
9.3518068 13.4419573 8.703402
5.0450231 7.1061948 9.331137
12.1339700 11.0707032 11.026477
7.6022791 7.1570958 10.794852
11.5544200 13.5178517 10.208971
9.0974730 6.2826785 11.793988
7.3821108 6.6169198 10.422196
1.4170253 1.2336912 10.746884
18.3644814 17.0202375 10.576442
15.5477742 17.0343885 9.689350
1.5698086 -1.5347856 8.953845
6.5729543 4.9161911 9.457498
11.3733720 13.2376450 9.756458
15.5208952 15.8739227 10.038682
8.0009616 9.9552670 8.750561
8.9411047 7.4909172 10.536542
7.3004604 4.7723257 10.114183
4.9387344 4.9036235 8.626765
12.7048744 11.0034054 10.687102
7.3588915 5.5611632 9.211927
15.7344196 10.0971091 10.288107
8.4218641 10.3514515 9.015701
12.0718345 12.5924408 10.411492
5.9196390 1.9271646 9.859441
8.7691837 12.5698462 7.784129
10.2343046 8.8974741 10.533850
8.0360949 10.7956057 11.352095
12.7183437 10.8810200 11.030304
9.1593065 8.7555054 10.421857
10.0775911 6.3959064 10.901516
11.7098247 10.8627988 9.824191
5.8158801 8.1385278 8.604800
1.9549774 2.3698850 10.054570
12.7606835 11.0077761 9.846111
5.4983952 5.4723696 9.874036
7.3275652 6.7767945 10.492721
12.3810422 12.7074250 10.012970
11.9871982 13.0982813 9.266071
7.8020130 5.4738611 10.143984
5.3249288 5.7057416 11.962245
1.7196803 1.7033602 9.024309
19.6614238 17.5724520 8.237204
11.6491358 14.3463863 11.613147
5.6752094 5.5165495 8.609122
10.8686325 8.7561970 10.022731
12.6765791 11.7271709 9.926925
14.1393928 16.1482069 10.032523
8.8757410 8.5907711 8.833402
1.1303913 4.6908344 10.321996
12.1842307 10.6789674 9.909078
7.5787223 5.2684228 9.589380
4.6565746 3.4912547 10.614561
17.0445525 14.4776787 10.943802
14.7219230 15.0223685 9.983696
17.5982859 16.9428604 8.717461
8.0116691 10.3760178 10.672209
15.4636080 17.3871700 9.225940
10.5611233 8.2635703 8.568831
12.1221658 11.5798554 9.690936
13.7538879 16.3918252 8.814427
10.3207457 9.4083205 11.822636
9.1263326 8.6572432 11.403034
11.8016119 13.1408181 9.775305
13.4433660 12.1713322 8.254470
4.0472676 7.8468515 11.000664
12.9829909 11.8756227 10.113189
8.9665867 8.5724369 10.398141
5.7077018 5.8194759 10.134961
11.7180619 12.0868329 9.608587
12.8895268 11.8327099 9.202267
3.1135552 0.6113114 9.431592
3.0256686 -2.1038017 9.813040
15.1034479 12.0062436 10.567009
16.6948250 16.6987174 10.613143
9.8892482 6.9220014 8.973916
18.5494373 19.9337068 9.053328
7.2229705 7.6700820 10.556468
2.8104295 3.0214804 8.246579
7.2872443 3.6619946 9.149129
9.4306904 6.7342818 8.861815
11.3442568 10.6294914 11.980732
6.5849500 4.7622979 10.444377
16.3609667 16.0678894 9.476815
5.5168893 5.3785773 11.386265
10.2639241 9.8891438 9.868259
9.6294210 10.5454956 8.582970
7.0309316 9.3164396 12.091511
10.4581266 10.8594627 10.519711
7.9429293 10.2603688 9.932533
4.4507937 5.2821483 9.812973
8.3041104 5.5666432 10.094316
12.8483956 14.0678728 10.496607
11.1588761 12.3459495 10.404245
10.6085807 12.6888866 8.984637
4.4588103 5.1615986 9.498537
6.4027510 7.8689446 7.977405
15.9461913 17.7897972 9.945959
16.8967308 12.9319482 9.699929
16.9058757 15.3691318 8.363673
12.2319230 14.2620913 9.853102
11.5495996 11.6939306 10.317926
17.1357742 16.3572742 10.544338
9.1524803 8.7122919 10.825238
2.5360347 4.0272128 10.615152
13.6994963 14.6682211 8.438240
9.8212832 9.3444553 11.483048
15.7556161 16.4445036 9.079870
5.9305872 7.2479710 9.283617
11.0808536 13.2868783 11.075598
6.8183193 7.0346528 10.950995
8.5718263 6.3714109 10.234464
12.0748376 7.4195380 10.979132
6.9204449 6.6774351 10.064719
4.6539317 4.5402173 11.846766
11.5815985 10.0136867 10.294231
6.8334930 7.0178975 10.012803
14.4205921 13.0352951 10.614363
11.8281129 13.1967944 10.104034
14.1764885 13.3826245 9.239959
11.4915329 13.3390902 10.890396
14.2801822 11.7329706 9.711738
5.2155991 4.3230762 9.924641
9.5425587 9.1459009 9.721926
9.5767530 8.8290638 9.983013
21.9731524 23.9302035 9.904114
3.4136170 6.8984582 10.741152
5.9487429 7.6488919 8.767769
9.6713090 14.0602366 9.389404
-0.9099282 -1.0048141 8.851437
9.7125421 13.2802435 9.294742
11.2281587 9.4557477 10.968568
13.8290823 11.6237675 10.003799
9.5344285 14.7243159 10.911425
3.4091018 2.2723223 8.147142
14.9818974 15.8558091 10.317356
14.4628626 14.2377061 8.674906
6.3218615 8.3580478 9.879770
6.7645510 6.3172950 9.879965
13.5518213 14.6546471 10.575422
7.1674847 6.6456323 9.654808
5.4950759 3.4214260 8.998009
13.8436434 13.0187867 10.574394
11.5120616 12.6242927 9.942859
9.5946828 9.0643648 8.037029
9.0777359 7.5876134 10.831029
13.0180532 14.7268090 11.158064
10.2668677 11.6735254 9.981412
13.6887330 13.5260161 9.992270
3.2751260 2.1170206 9.500418
11.5854491 14.7531942 8.831352
8.1633616 9.0876237 8.893885
7.9765102 6.8111679 11.331588
12.3233157 13.6444916 12.381135
7.1685275 6.9039198 10.772948
9.5387475 13.2576412 9.974691
14.5607344 11.2906663 11.202767
12.1050876 13.9647819 10.235030
4.4555067 1.8832556 11.554996
7.6169662 9.0448644 9.308438
3.3070220 4.4078185 10.698471
5.0992079 4.9488223 9.963070
8.2363816 4.4070045 9.269677
11.3236512 9.9518041 10.055856
10.1562227 9.4292973 11.073055
11.3476432 11.7371411 10.742966
9.7826278 13.7361096 8.983404
1.1824546 1.5082695 8.844103
16.5319305 13.5130863 10.443175
13.8889147 16.0058005 10.515182
10.0656734 10.0131498 10.138251
13.8562246 11.9989727 12.259664
13.9715235 15.0007625 9.940886
13.8168620 12.5668466 10.409207
12.0683070 12.0397939 10.578609
10.2997871 9.0990525 9.040938
9.2197060 9.0040769 9.978597
7.7158831 10.9173142 10.378647
11.6970183 11.4844030 9.931428
12.4648866 11.6527273 9.847117
11.3256069 11.0615573 10.852062
10.9224254 6.8806038 8.039382
7.7482346 7.2277663 10.726829
15.4013534 15.8341037 11.528444
6.2891499 7.8143445 10.370561
8.6503558 9.5204039 10.729181
19.5732695 19.1780049 11.197212
11.5489007 10.7795017 10.326631
6.5335934 5.4788297 10.123073
4.8379679 5.1858628 9.082168
11.2348729 12.0335386 10.298124
14.6721145 12.4994207 10.835795
14.4117302 16.9542621 10.160365
8.2865719 7.3930510 9.410131
13.5035226 10.9778873 8.772734
8.5170672 6.5208795 10.288619
13.2128347 13.5958243 11.808395
15.9817276 14.9986840 9.426795
11.9778315 10.4199589 9.688980
10.7339553 10.5070032 9.979141
9.3394071 11.7833203 10.890564
1.1944117 0.8155077 9.988236
6.3040093 5.2484415 11.495680
10.2648521 10.1210595 9.279155
2.7413010 2.3315670 8.291667
12.0354059 11.3022123 9.059469
6.8502923 4.4531242 8.984131
16.1211721 16.2178521 10.590746
12.5740054 10.3193883 9.912629


And here’s how they look like

plot_ly(df, x = ~X1, y = ~X2, z = ~X3) %>%
  add_markers(size= 0.5) %>%    
 layout(scene = list(xaxis = list(title = 'X1'),
                     yaxis = list(title = 'X2'),
                     zaxis = list(title = 'X3')))


We can see there’s a some sort of correlation between \(X1\) and \(X2\) that are mainly spread along one direction. We can think of this direction as the place where there is the most of the total variability.

If we look instead to the \(X3\) axis we may see there’s another source of variation, smaller than the previous one.

We might say there are three principal components of variation, one bigger than the others.


To correctly perform PCA main components must pass through the origin . The so-called mean centering is carried out, which consist in subtracting for all values within each column their mean.

This procedure is mandatory in most of the cases when you carry out a PCA because we need major component to go through the centroid of the data.


\[ X^*_{i,j} = X_{i,j} - \overline{X_i} \]


df_scaled = scale(df, scale = F) %>% data.frame()

plot_ly(df_scaled, x = ~X1, y = ~X2, z = ~X3) %>%
  add_markers(size= 0.5) %>%    
 layout(scene = list(xaxis = list(title = 'X1'),
                     yaxis = list(title = 'X2'),
                     zaxis = list(title = 'X3')))



Now we can generate the covariance matrix.

cor_df = cov(df_scaled) %>% data.frame()
kable(cor_df) %>% kable_styling(full_width = FALSE)
X1 X2 X3
X1 15.3790481 15.0952951 -0.1034882
X2 15.0952951 18.6198889 -0.1043137
X3 -0.1034882 -0.1043137 0.9753565
pc = prcomp(df_scaled)
pca = summary(pc)
ggcorrplot(cor_df,  
           type = 'full',
           method = 'square',
           lab = TRUE, 
           lab_size = 5,  
           colors = c("tomato2", "white", "springgreen3"),
           title="Correlogram", 
           ggtheme=theme_bw)


General formula for covariance between two variables \(X\) and \(Y\) is

\[ cov(X,Y) = \frac{1}{n}\sum_{i=1}^n(x_i-\overline{x})(y_i-\overline{y}) \]

We call this matrix \({\bf C}\) and, since is a square simmetric matrix, exist in \(\mathbb{R}\) an eigenvalue \(\lambda\) and an eigenvector \({\bf v}\) such that

\[ {\bf Cv} = {\bf \lambda v} \]

In other words, vector \({\bf v}\) is scaled by the matrix of a factor \(\lambda\), which is basically the amount of the total variance.

In our case there are three eigenvalues (one for each variable) and three unit eigenvector.

eig = eigen(cor_df)
eig
## eigen() decomposition
## $values
## [1] 32.1821776  1.8175124  0.9746036
## 
## $vectors
##              [,1]         [,2]         [,3]
## [1,]  0.668299939  0.743830506  0.009558751
## [2,]  0.743877057 -0.668312644 -0.002265958
## [3,] -0.004702745 -0.008624876  0.999951747


A nice property of eigenvalues is that their sum is always equal to the trace of the starting matrix.

The total variance in our case is then divided into three components according to the size of each eigenvalues, which are in fact the measure of the variance for each component.

When you have a lot of variables may be convenient to express them in percentage

eig_prc = (eig$values/sum(eig$values))*100


eig_df = data.frame('PC' = c(1:3), 'Var' = round(eig_prc, digits = 2))
eig_df1 = eig_df
eig_df1[2] = data.frame(lapply(eig_df[2], paste0, '%'))

kable(eig_df1) %>% kable_styling('striped', full_width = FALSE)
PC Var
1 92.02%
2 5.2%
3 2.79%


And put those values onto the so-called

Scree plot


ggplot(eig_df, aes(PC, Var))+geom_col(width = 0.8, fill = 'cornflowerblue')+
  geom_line()+
  theme_bw()+
  labs(y='Explained variance', x='Principal components')+
  geom_text(label = eig_df1$Var, nudge_y = 5, nudge_x = 0.1, size = 3.5)


Eigenvectors however tell us the direction of the variance, and there will be one unit eigenvector for each source of variance, i.e. for each variable. They are also necessarily orthogonal to each other.

Let’s see what happens if we plot them onto a graph.

eigenvectors = data.frame('v1'= eig$vectors[,1], 'v2'= eig$vectors[,2], 'v3' = eig$vectors[,3]) %>%
t() %>% data.frame()

plot_ly(eigenvectors)%>% 
  add_trace(x=~X1, y=~X2,z=~X3, 
            type = 'scatter3d', 
            mode= 'text', 
            text= c('V1','V2','V3'),
            color = c('red', 'green', 'blue'),
            showlegend= FALSE, 
            textfont = list(size=16) ) %>%
  
  layout(scene = list(
                 xaxis = list(title = 'X1', range=c(-1.5,1.5)),
                 yaxis = list(title = 'X2', range=c(-1.5,1.5)),
                 zaxis = list(title = 'X3', range=c(-1.5,1.5)))) %>%
  
      add_trace(x=c(0,~X1[1]), y= c(0,~X2[1]), z = c(0,~X3[1]) , mode= 'lines', type='scatter3d', name='V1', text= c('V1','V1')) %>%
    add_trace(x=c(0,~X1[2]), y= c(0,~X2[2]), z = c(0,~X3[2]) , mode= 'lines', type='scatter3d', name='V2', text= c('V2','V2')) %>%
    add_trace(x=c(0,~X1[3]), y= c(0,~X2[3]), z = c(0,~X3[3]) , mode= 'lines', type='scatter3d', name='V3', text= c('V3','V3')) %>% layout(scene = list(aspectmode = 'cube'))


Actually there are infinite eigenvectors but computer software give us back only the ones with length 1.

Since we said eigenvalues express the amount of variance and eigenvectors are his direction, we just combine these two pieces of information to get vectors with length proportional to the variance.

eigenvectorsM = eigenvectors %>% as.matrix()

# --- multiply each eigenvector by corresponding eigenvalue ---

loading_vectors = t(eigenvectorsM) %*% (sqrt(eig$values) * diag(3))  %>% data.frame() 

colnames(loading_vectors) = c('P1','P2','P3')


loading_vectors
##             P1          P2           P3
## X1  3.79122129  1.00279618  0.009436592
## X2  4.21996528 -0.90098667 -0.002237000
## X3 -0.02667836 -0.01162764  0.987172494
loading_vectors = t(loading_vectors) %>% data.frame()

plot_ly(loading_vectors)%>% 
  add_trace(x=~X1, y=~X2,z=~X3, 
            type = 'scatter3d', 
            mode= 'text', 
            text= c('P1','P2','P3'),
            color = c('red', 'green', 'blue'),
            showlegend= FALSE, 
            textfont = list(size=16) ) %>%
  
  layout(scene = list(
                 xaxis = list(title = 'X1', range=c(-10,10)),
                 yaxis = list(title = 'X2', range=c(-10,10)),
                 zaxis = list(title = 'X3', range=c(-4,4)))) %>%
  
      add_trace(x=c(0,~X1[1]), y= c(0,~X2[1]), z = c(0,~X3[1]) , mode= 'lines', type='scatter3d', name='P1', text= c('V1','V1')) %>%
    add_trace(x=c(0,~X1[2]), y= c(0,~X2[2]), z = c(0,~X3[2]) , mode= 'lines', type='scatter3d', name='V2', text= c('V2','V2')) %>%
    add_trace(x=c(0,~X1[3]), y= c(0,~X2[3]), z = c(0,~X3[3]) , mode= 'lines', type='scatter3d', name='V3', text= c('V3','V3'))


IN PCA these linear combination are called loading vectors and they’re generally indicated with the letter \({\bf p}\)



Now, let’s take a step forward and take a look what happens when we project the original points on these new vectors we just found.

We want to know, in other words, how much each object weighs in relation to principal components.

In mathematical terms this is a linear combination and it’s something like this

\[ PC_{i,m} = p_{i1}x_1+p_{i2}x_2+...+p_{im}x_m \]


Where every \(p_{i,m}\) is a loading vectors component and \(m\) is for the number of total variables in the data matrix.  

Or in vector notation

\[ {\bf PC_1} = {\bf X \cdot }{ \bf p}_1^T \]

What we’re doing is a change of base. We want our principal components vectors to be the axes of a new reference system.

In math terms we say they are an eigenbase of the original matrix, namely a set of vectors all linearly indipendent.

score_df = as.matrix(df_scaled) %*% t(eigenvectorsM) %>% data.frame()
colnames(score_df) = c('PC1', 'PC2', 'PC3')

kable(score_df) %>% kable_styling('striped', full_width = FALSE) %>% scroll_box(height = '500px')
PC1 PC2 PC3
-13.4171015 0.7879534 0.6369618
-1.5393342 0.0210064 1.4476258
5.0395433 -0.4766111 0.2341523
1.0558323 0.3776907 -0.8736625
-2.3715902 1.3806645 -0.3300249
-3.5423936 0.3768586 0.5052218
-5.7494751 -0.1008909 -0.4960008
-5.4753236 -1.7041371 0.8459553
-4.6880618 0.2575638 -0.2035494
-0.1945283 0.4957722 -0.7846391
4.8686011 -0.9562464 0.4575672
-2.6283009 4.2431773 0.4034207
1.1200307 -1.5336407 -0.9234914
-2.0628102 -1.9667308 1.5434761
2.9648056 -0.3910680 -0.2107552
-1.1787864 -2.3865572 0.9188736
-5.3426696 -1.5653526 -0.4619930
-2.8112533 -1.5462930 1.3901882
1.6154570 2.0415027 1.4561298
1.2331807 0.4368870 -2.1056991
-6.2771868 -1.5506798 -2.1351446
-1.7173480 0.3576685 0.8508387
-7.7647250 -1.7233660 0.3806404
-3.4481908 -0.5470313 -0.1401546
4.6818981 1.5366151 -0.2278794
-6.9499660 -0.4075689 0.8498222
0.5947152 -0.5169987 -0.4833229
-6.2501772 0.4995401 -0.7276035
-4.4485323 2.1062897 0.0748915
2.4553021 -0.8033809 0.0346638
-3.2291676 -1.9253701 -1.7841818
-4.8082865 -0.1852000 -1.5476798
1.5410889 -1.1812222 0.0396794
4.2675020 -1.7408384 -1.3726609
1.9733408 0.6885874 0.3218777
2.7948875 -1.6738866 -1.0259552
-3.1314918 -0.9320421 0.2853726
7.1503632 2.5907220 0.6577619
-7.0797938 1.0886036 2.2462150
2.3054302 -0.7913308 1.6864231
-8.3174156 -1.0093712 -0.9893626
2.9271195 -1.1026644 -1.4550289
-6.5253653 -0.8465690 -0.5599108
3.4502362 -0.0893018 0.4295759
-6.9932101 0.3279421 1.0782849
0.9321347 2.8804736 0.9442281
0.6859240 0.4205606 -1.0404146
4.2230834 1.7760603 -0.5378670
0.0568885 0.5615439 -1.7279829
-10.6061161 0.4953637 -0.0957531
6.6113966 -0.3813882 -0.4297194
6.0452884 0.1311504 0.3073498
-3.5954526 0.0670449 1.1461960
0.6017905 -1.8710084 1.1593452
-7.7049532 0.8354485 0.9516502
-3.0191111 1.2163348 -0.4460842
14.8952262 0.2874039 -0.2943506
-2.1895491 -1.0617378 1.1460359
8.5293116 1.3948441 -0.6385691
-7.4999767 2.1963904 1.6408658
-3.9053975 -1.2542198 -0.0215715
-5.2683609 1.2053354 -1.2321280
-3.4984573 -1.0678043 -1.4913291
9.4187550 -0.3060457 -1.0831411
5.4190573 -0.5983775 1.2513247
-12.6625037 1.3589690 -0.9217672
16.4502850 0.2025839 0.2542167
7.4278183 0.6571287 0.8048283
1.0596028 1.9362029 -0.5941284
-1.3287573 0.6210634 -2.2148686
-3.4891880 1.7689611 0.4811766
-0.3886649 -0.5009157 0.6153022
-3.2755824 0.8483673 -0.5596840
3.2973537 -0.7744949 0.8870002
-8.2589307 0.2607292 0.5631166
-7.0308887 0.0473763 1.2108982
0.5163172 -0.2703000 0.1854430
0.9356057 1.8070197 -0.0953003
-3.1079753 0.3585780 0.3726556
2.3397658 -0.0988136 -0.5162754
4.2064085 1.9031759 1.7036206
0.2090415 1.6534174 -0.2202389
-6.3541018 -1.2426658 1.2066865
-11.6390728 0.7327805 -0.2028109
8.0469050 1.8165300 0.1971718
-4.7389478 -0.4843509 1.1308066
5.9006101 -2.8053690 0.3163928
4.3649488 -0.0951072 -0.3085381
-8.3913941 -1.2923330 -1.0030678
0.4722257 -0.3469402 1.4223190
-0.7566188 0.6083378 2.0450901
-7.5463108 0.7207382 -0.0663079
0.7992862 -0.1701018 1.1886162
11.2096651 0.3831892 -0.6330605
-6.2019528 -1.7042221 0.4910349
-8.0072415 2.6706098 0.3355901
2.0504926 1.6204523 1.3914569
-11.1120061 0.0540567 0.2700058
2.2684641 1.6015741 -0.2568001
3.7458999 1.9141189 0.3899050
-10.8341899 -0.1277626 0.8285801
0.8840102 -0.0292787 -0.8633877
7.0399099 0.6002471 -1.0337461
5.8099035 -1.1007259 0.4875509
2.8584734 2.4691779 1.9667436
0.3847595 0.7929192 0.3705107
-4.1425862 -1.5602946 0.5694364
0.8712011 -0.7765461 0.2723086
5.5960635 -1.0827488 -1.8747434
8.1835846 1.2655279 0.5623219
7.5109536 -2.2951363 -0.8272072
2.8346006 1.1757939 1.4333180
-2.9616722 -0.3061198 -0.6192568
2.2282370 -1.0861900 -0.5509208
1.9470668 0.7289712 -0.6785977
-5.1643838 1.2016086 0.9144222
-2.3737536 0.9593800 -0.4958221
-3.6921403 -1.2308822 -0.0432541
2.9365964 -1.4259718 -0.1194540
-1.0649795 0.2514830 -0.2149569
2.1407988 0.5928182 0.4552758
2.7160331 -0.8851924 0.0447897
4.6646245 0.7318531 2.8982521
5.5595718 -1.3668212 -0.5025575
0.5391326 0.3089075 -1.4085179
-0.6807228 1.3366780 0.2592128
-2.0857340 -0.2438065 0.4992782
-2.8530076 -1.5467172 1.8926563
-5.7617959 1.4199636 -0.3889384
7.5405551 -0.4516543 -0.9496652
4.7645362 0.4470925 -1.4896645
5.1560132 0.3857235 -0.1296043
6.4260134 -0.7574900 -1.8092168
5.4856145 2.1217953 0.3554834
-1.4288463 -1.1458354 1.2300776
5.8688516 2.3940138 -0.2993527
0.3214705 0.7734009 0.3134629
-17.1156027 -0.2616274 0.5456769
-4.5665818 -0.2385068 -1.0960529
10.8327559 -0.8734336 0.2555782
-4.3567313 0.3967210 1.3266129
1.6118495 1.1944775 0.3451578
1.5960908 -2.2373442 0.0734613
5.2039191 -0.4527797 -1.5752736
5.5771191 0.0866233 -0.2665111
2.3867565 -1.8126912 -1.2621568
-5.2282059 0.5756950 -0.2736282
5.4583582 -1.8540516 -0.9939857
1.8101229 0.0550537 1.2011928
-0.4980559 0.2349843 -0.1919741
-0.7105047 -0.7244536 0.9233657
3.5824348 -0.0017546 -1.3095819
1.4915362 0.4244177 0.6890583
-6.0910612 1.0767096 0.1830791
-0.8373363 -1.3639985 -0.7349359
6.6651232 -0.1147242 0.2379158
-0.8762900 -2.5800084 -0.6214770
6.8984813 -0.3006394 0.5154695
-5.5672699 0.9899525 1.5857272
-6.4550087 0.4861817 -1.8396837
2.8980931 -0.6792805 -0.1571772
-0.6191372 0.5326599 0.8430943
-1.1966688 0.6725847 0.4419648
-6.8948035 -0.3405114 -0.8361589
5.0987031 -2.5986932 -1.6946319
2.7789567 -1.4972994 0.3608372
-15.6216836 1.0229628 -0.0900485
9.5946785 0.1870258 0.2224639
-0.1814152 1.8055434 0.2142840
-4.7224981 1.3566721 -1.7507036
7.4803902 -2.2682319 0.4534795
3.3226200 0.6866567 0.0011150
-8.0345287 0.6197683 -0.1336785
3.1568617 -1.5910847 -0.5265575
0.2072939 -1.1173694 0.0176582
1.3438720 0.2845117 -0.3170181
0.3033525 -0.4551261 -0.7735222
-0.7373300 -0.3923206 -0.8161232
3.6860560 -1.4280206 -1.6154515
2.5455645 -0.2287623 1.3336232
-2.9484172 0.7078828 0.3063875
13.7669301 -1.1304284 0.9382965
0.8659473 2.4161248 1.9087794
8.4261099 -3.8565318 -0.2270955
1.3956935 -1.0262804 -0.5426285
7.2132996 0.9486712 1.8502852
-0.0948177 -2.3045746 -0.0861902
-1.7280914 -0.3351766 -0.1076903
-9.7294999 -0.9793816 0.7311397
-9.6260346 -0.2201708 1.5270085
-0.9865841 -1.7594040 2.2579230
-1.4905083 -1.3055236 -0.4577482
4.0494002 -1.4830657 0.0954168
-10.4858860 -2.7563516 0.1112242
2.0150650 -1.6566330 -0.3160998
-13.5043858 -0.7047636 -0.7989145
5.5205457 -0.8330647 -1.8052011
2.0732221 2.6477062 -1.4110844
2.1485120 -2.1304063 2.4423295
3.3635710 1.8180675 -0.2923363
-6.9163484 0.0637339 -0.8121343
4.2597628 2.4863810 -0.0767921
3.0084524 -0.0727874 0.4423587
-5.7583168 -0.8880635 -0.3135923
-1.2028786 -1.2666029 1.0397887
3.2142210 1.5060207 -1.1137080
1.4294164 1.4708760 1.1372970
-8.9103070 0.6556590 -0.5016535
6.3121016 -0.1632592 -1.7470896
3.7394044 -0.3486151 -1.0308437
-0.5301745 -0.9999025 1.4331903
-2.3021142 -0.8395823 -0.1991792
-4.8779716 -0.0059093 -0.3313253
-0.5621133 -1.7772064 0.3488330
8.6643105 -1.1924806 0.7820598
-5.9235675 2.2031133 1.9753021
-0.1186315 -0.1510949 -0.5055804
-3.2725500 0.1336028 0.6960474
1.1431636 -0.5403533 -1.5118209
5.7202847 0.1492566 -0.5440075
-3.9958502 -0.5027638 1.8260232
3.9098962 0.3605165 -1.4642857
8.9931252 2.0472858 0.4410675
-10.9809679 -1.6597135 0.2441775
3.2018470 -2.7010090 0.5069528
14.1624196 0.7917502 1.0050075
0.9112642 1.9934276 -0.2752984
-8.1211605 2.5706439 -1.1183322
3.9007847 0.4543430 -0.3065684
3.5386701 -0.9507995 0.5421039
-1.2981908 1.1983188 -2.2646499
1.3999434 -0.6926709 -0.9559613
3.8849669 0.1181395 0.6982321
8.4622429 -0.4407876 -2.1913635
8.1325426 -0.4621748 0.1534030
5.0595204 -1.1980223 1.7210322
6.6901823 0.4395198 -2.4069346
-8.7657342 1.6068078 -1.3564422
1.6188442 0.8847288 -0.8721751
0.5641085 -1.0284059 0.3459024
1.7610046 -1.2904884 -0.0536365
-4.1001004 -1.8485222 0.3586231
-2.1273918 0.0502203 0.5899346
-4.4981023 -0.6686103 0.9392437
2.5321845 -1.0167966 -1.2995027
-5.9356138 -1.1258867 0.1979384
3.4064994 -1.9198656 -0.0189448
9.9225438 -0.7470972 0.0105530
-3.0910284 0.0204041 0.1313612
-2.6068700 0.9410415 1.5601939
-3.1461556 0.9931329 -0.2661703
1.7454907 -3.3103130 1.3353513
-1.1947682 -0.7882338 0.7511263
-1.7315329 -0.1830317 -0.9878394
-1.7873392 -0.8447994 0.2665092
3.4344579 -0.4911246 -1.8134353
-8.0890299 -2.9929957 1.6961864
1.1185741 -0.9581170 0.0111400
-4.1170890 1.8617456 0.3923003
-3.3084069 -0.6126929 0.3950104
7.2672757 0.1072056 -1.7344339
-3.5772825 2.3181867 -0.3636362
6.4157812 0.7693051 -0.7854858
6.8266262 0.0347887 -0.8371262
-2.2713907 1.1179276 0.4179706
-4.6352003 -0.3804351 -0.6836175
-3.6995388 2.1382045 -0.3537914
-6.4192633 1.0139380 -0.8312551
-10.9478813 -1.5340360 -1.0682939
-0.8072182 -0.4920762 0.8508653
2.8384938 -0.7679038 0.2474091
7.7306136 -0.8300418 -0.1716735
3.7958173 0.3587378 -0.3750794
-0.7927991 0.8611039 -0.4208075
1.3611991 2.6274060 2.2607420
8.0209358 -1.5144073 -0.0170342
1.7719767 -1.5466034 0.3825924
-0.8033174 1.1665785 0.3477276
0.3712076 -0.2890308 2.2866570
6.0696495 -0.4770749 -0.8632319
6.8811154 0.3594393 -0.8692073
-3.2986966 -2.5381234 0.1038488
-7.5339875 -0.1762620 0.7547207
-2.6177607 -1.0764144 0.1064546
5.1540908 1.0069507 -1.3178865
8.8244493 -1.1701415 -0.1153352
-5.8647073 -0.2396385 1.4382719
-4.5016224 2.2179178 0.0924638
9.5817201 2.1059039 -1.0879871
2.7357650 -0.6236535 0.5985752
-11.0965445 -0.1874953 2.0401713
7.4116554 0.3428527 1.6660760
2.1752540 -1.2546313 -0.9418405
11.7638610 -0.1551225 -0.4221122
1.2589906 0.1358751 -0.3339468
-8.8160304 0.0297242 0.1198186
3.5559550 0.3313441 -0.8111912
-0.9105108 -0.6324023 0.7536115
-10.9234784 0.8053773 0.8593085
-3.2706638 -0.8996331 0.1859203
0.9882796 1.4998695 0.3860895
0.1701805 -1.5819203 -0.6802877
-5.5049840 -0.0499590 1.7970354
2.5880247 1.3628944 0.8623565
-5.4241849 -0.1290419 0.2646632
10.7177187 -0.2117868 0.4388317
3.8648356 0.8175232 0.0025547
0.6783062 1.8888739 -1.4145997
3.6478722 0.3852348 0.0436856
-0.4034914 2.1312509 -0.3170061
-2.9464351 0.5451353 -1.5238556
2.5875499 -0.6365405 0.2971632
-4.1598564 -0.2734841 -0.4599952
4.1826670 1.7218345 -0.8611433
-10.4654232 0.6191204 -0.0491820
10.4415944 0.9941033 0.0529230
-0.6851429 0.8174154 -0.4136908
-2.7802942 1.7280376 -0.1051805
-9.5105149 1.4731899 0.6464321
-15.3941502 -3.3758585 0.7401900
3.5671913 0.6911670 -0.5654420
3.8167740 0.2159287 -0.4011021
-3.7266025 -2.6616297 1.0101977
0.2027187 -2.0249847 -1.2561844
-4.1460069 0.9844285 1.4730442
-3.3692404 -0.5066292 -0.4733522
-3.7761667 -1.3094903 -1.4500857
1.8864983 1.0011506 0.2031000
-3.9158740 -0.0798551 -0.4731075
-1.3645587 -1.3839125 0.4694806
2.0186260 0.0525926 -0.4444815
-0.1530085 0.3090040 -0.5863901
4.2149710 0.6413529 0.5583620
2.8481419 1.0356780 -1.1430639
-2.1056717 -1.2583919 -0.1222218
10.4445600 -0.4117549 -0.6981981
-0.1079859 0.1735512 0.0710848
8.3127335 0.1017170 2.1218543
1.3131694 0.1389534 -0.0983702
5.7614314 -0.4785019 0.1130207
-5.3440671 -1.9049814 -0.8747673
-6.6998790 -0.2480314 -0.5509347
11.3625073 -0.5934202 -1.0808178
-1.8319882 1.8424110 0.6046768
-5.8998050 0.1792291 1.8032376
-10.8189408 -1.6894121 -0.6266701
4.9378383 -0.4805021 -0.8773710
-2.5863793 -0.8527158 -0.8547998
-6.0927208 -0.7008917 -1.0716322
2.3111618 0.5062575 0.1429993
5.9803515 -3.0795480 -0.7591213
6.9094609 -0.4258624 1.7420917
-4.2306462 -0.9017127 0.3313290
0.9040562 1.3499321 1.4220786
4.9944785 1.1466112 -0.6936865
0.3003255 0.7378046 -1.1736979
-6.9033128 2.7047868 -3.1682349
-11.3915259 1.7225039 0.1827659
-1.0943561 -0.7200140 0.9402799
-2.0917014 0.4643375 0.1013545
-8.5903909 -0.3867933 1.7093838
5.6652256 0.4026755 -2.5297599
3.9361347 0.5695093 0.9663134
8.1455734 0.0972289 0.7735364
-1.3690039 -1.2078157 -0.5259536
2.4040625 -2.4925037 -1.7125888
-4.2752032 -0.6290917 1.5060621
11.3252368 -1.4749119 -0.0027289
7.7989432 -0.9528966 -0.1014908
-3.9239140 1.0795604 -0.7198633
0.9231511 -0.0935888 -0.6941215
-1.2465386 0.3969465 2.4371334
-6.8507276 -1.3622540 -0.6328517
-4.0601979 -1.8374702 0.1557911
7.4731259 1.9986563 -0.6197756
10.6743086 1.5026241 0.9625148
-3.0277973 2.5117849 2.1475136
-8.9975207 -0.7911363 1.3817585
8.4134732 -0.8360070 -0.3411453
12.2759040 1.9131771 2.0273686
-12.6036633 0.1289526 -1.0067742
0.5274720 0.5243596 -1.7538916
5.4768688 -1.2090090 -0.8376728
0.9790318 1.2214700 -0.7997176
6.2206571 2.6064276 -0.5237275
-4.6704073 2.2506870 -1.1566278
9.4350450 0.5773204 0.6022614
1.8114693 0.2095537 1.1477521
1.7036111 -0.7137363 1.1263676
-5.7831367 -0.0654286 0.0134706
3.0314666 0.7647634 0.0213952
-7.9381193 1.2073510 0.1856511
-0.2929753 0.2179408 -1.0585167
-0.8171354 -1.4871135 -0.4241831
0.2308709 1.7654699 1.1257485
-4.5702302 1.4840091 0.6763360
2.0776055 1.0041964 -1.0314314
4.4119378 1.5997525 -1.1030805
-3.0210941 -0.7024642 -0.2647897
-0.9167405 0.1344024 0.9098768
-4.6489315 -2.2725401 -0.3542855
-2.9427091 0.5532151 -0.4144294
0.5029565 0.6843869 -0.2302608
-1.3529776 1.9368043 -0.9000604
-5.8469389 -0.5966857 -0.0459633
-7.7113412 0.6615632 1.4809352
3.4962094 -1.1035791 0.4751173
3.3063963 1.0998091 -1.1805782
1.5223982 -0.6709290 0.9488546
6.3055388 0.0718347 0.3487772
-4.5610575 0.2659430 1.4915916
-1.0523398 -1.0492374 -0.8197282
-9.0242373 -1.0360945 1.6308416
-0.5888441 -0.7650855 0.1042194
-1.1139881 0.4233221 -1.4822484
-8.5855970 0.5453967 -0.3676316
-4.0172852 -0.6729986 0.4639152
-0.0664800 0.0513706 -0.5078873
3.5669967 2.0059825 -0.0855155
5.6807591 -0.0702420 0.5743243
-1.6120076 -1.6210931 -0.5149013
8.6553627 -0.9422957 -1.1553494
3.9259222 -0.0192409 0.6053401
-0.5799224 -0.4863678 -0.4105674
-2.0255610 -1.9418734 -0.1343732
-1.1950062 -0.4831905 -0.7037665
2.6081251 0.1544906 -0.9910406
2.4464288 -0.0639662 -2.0675375
0.6768899 -0.2688213 0.0541613
7.0564926 0.8553754 1.0532254
2.6617394 2.5120753 0.3356702
-3.7701627 0.3849460 -1.0095483
3.4657118 -0.7410261 -0.2340863
1.0109767 0.7504959 -1.4318155
3.2609710 -0.4136688 -0.0522983
-6.4312925 -1.0198796 0.3414631
7.3102551 0.1103351 -0.3488728
1.8102592 -1.8591372 0.1980386
0.8777775 -0.0801202 -0.1471367
-6.6322315 -0.0250863 2.4176658
5.6764799 1.8118540 -0.1156664
7.4403761 -0.2823390 1.9072532
-2.3133145 1.2488617 -0.6419327
-0.6226652 0.1623518 0.4854912
-1.9722673 1.9951240 -0.2858282
5.6928813 -0.8727320 -0.8490247
5.6668672 -0.4185084 0.1902116
10.6492260 1.5915859 -0.8205634
-2.7509972 -0.6666676 -0.2143068
4.4478255 -2.2259752 -1.9787014
4.1824086 0.1031296 0.8390421
-7.6970387 -1.1613351 0.8330815
-4.0922326 1.0139175 1.9230094
9.8967336 0.1553674 0.3107965
-0.8190926 -0.0924823 -0.2791473
3.0832885 -0.8068659 -1.0010241
3.0103208 -2.0644954 0.5866305
2.3278436 -1.1342111 -0.2479085
-2.0206339 -0.8569242 1.3874526
-0.3291234 -1.9321412 0.2166195
-8.6596687 0.3858018 -0.9700372
9.5160243 1.0736776 -0.7422277
10.1682424 0.5513433 -0.9556347
-4.0924806 1.3824492 -1.3332778
14.3546038 -0.1688482 -0.7742627
11.2749280 -0.9628294 -0.0759644
-14.0608623 0.6761403 -0.4075437
2.8539076 -0.5694850 -1.6955692
6.0533799 1.2837944 -1.1588929
0.0698863 -1.7326306 -1.4131420
-1.0413503 0.6649885 -0.7798778
5.4730704 0.4611009 -0.3544632
-3.1517365 -0.6787187 1.0699665
2.6337632 -2.6204285 -0.7185852
4.4440312 -0.9481963 -0.5924823
4.6905575 -1.8838752 -0.0326067
2.2088272 -0.7077515 1.3122048
-7.1481058 0.1093931 -1.0602146
-5.1449101 0.0880317 -0.4875028
0.3994938 -1.1591622 -0.4330399
10.4166783 -2.1927221 2.0810919
9.0188036 0.6073320 -0.7500554
2.2800085 -1.7076628 0.0199029
1.9817922 -0.0937303 0.2483965
8.0129213 -2.5180644 1.0775922
2.7330157 -2.3881550 0.3476087
-2.2564369 -1.2660527 2.8889643
-3.0524431 -0.4147548 0.0772343
3.1725196 0.5935226 0.9012530
2.0480610 -1.0201768 0.2837914
2.4047853 1.4811252 0.1513779
-6.6217633 3.1889509 0.1896688
4.5244179 -0.1695850 -2.0259375
-2.4664677 0.3314490 0.5326158
2.4307992 -0.6036295 -0.5247150
-3.6081154 3.2075584 0.2150100
-11.6353177 2.1825778 -2.0849682
-5.0028860 0.8164104 0.0556837
-3.1576815 -1.8776134 0.0734346
0.6381455 -0.7394312 0.2549965
3.4275577 1.9932798 -0.1151178
-7.4693522 0.1187034 0.3493514
-1.3854613 0.9343564 -1.1542878
4.1926692 1.1987055 0.8419351
-2.6258104 0.0256418 -1.6372906
0.3429979 -1.9840968 0.0786348
-6.7423740 -1.0069096 0.6679041
2.5705220 -0.3823683 -0.0725255
5.8298094 -1.9133395 1.9961583
-6.4301344 2.8456431 -0.3804299
0.8150599 -0.9092613 -0.5124232
4.4539559 1.3133799 1.1543210
-0.3201336 2.1990858 -0.9572742
-11.4993919 3.1461806 -0.9881627
-2.0461578 -0.3422701 -1.1425680
-9.8738352 1.2971758 1.0923032
13.5504598 -0.6124711 -1.2029064
-4.9250437 -1.0647769 -0.0553332
-2.6240553 -2.1659354 0.5040299
-2.1815074 -1.2535695 0.1856149
-1.3998347 0.8667820 -0.6259688
8.6057828 1.5503163 0.3402412
-0.9637984 1.2173132 1.2242154
-2.1963056 1.5320914 0.0183785
-1.7475548 -0.1164874 -0.1049482
8.8182454 -0.8938376 -0.6185704
-10.5936517 0.4346154 -0.4617796
5.5294103 -0.5168853 -1.5453898
5.9956015 -2.5332921 -0.1355444
4.7817988 -1.4792640 0.1181324
-6.2346153 2.2510031 -0.8209640
-1.3163143 3.6098975 0.3938024
-3.0435162 -0.2373644 0.4985961
-4.1628840 -3.7346026 0.9263671
6.9913958 -0.0475899 0.1201408
-0.8033637 2.7794206 1.9560983
2.5981581 -3.3588390 0.2350946
-4.2362815 2.3984446 -2.2663947
0.2592182 0.2134418 1.2568017
-5.7598470 0.7786483 0.4565084
-2.1744647 -0.6256888 0.5437377
-1.1582054 1.1309852 -1.5292632
4.0974058 -0.2044333 -0.9753380
-6.7543443 -1.2589601 2.1260237
5.3984036 -0.6774956 0.1246402
-8.5958191 1.4555129 -0.4772564
3.6418209 -0.7978514 2.7027799
-11.2035472 -0.2522092 -0.1094401
-1.5036234 -1.5115207 1.0296592
-2.7586642 1.4030653 0.0428611
-5.4384042 -2.5574261 -0.0953628
-5.3838479 0.2123001 1.6856651
2.3592171 0.8654783 1.8896920
-0.0322101 2.2612650 0.4765500
-9.4817420 2.2026002 -0.6690589
0.0973185 -0.3694571 -2.5941841
-6.8046387 -2.6562980 1.2491275
0.5955091 0.3046213 1.2023504
-4.6898154 -2.5892012 -0.1011167
11.7874115 -0.8594660 1.0054117
2.2412424 -0.5933105 -0.5699080
-8.9400803 0.0179542 -0.9330257
-7.1564296 -2.0035539 -0.7321489
-1.8434543 1.7011015 -0.9389838
1.8129313 1.6110210 -0.8663181
-6.8724558 -1.0011656 0.5427613
3.2998954 -0.7156309 0.9950155
-3.5921739 -2.8530197 0.2180805
5.5823596 -1.8095867 0.9206199
3.0212637 -1.0138676 -0.2969028
-4.6267177 0.8092698 0.0143971
-4.1980424 -0.7256504 0.4032971
-0.0641953 2.2619919 1.0864732
-7.2994065 -2.0400362 0.0535776
-5.0006777 -0.5110592 -0.8273827
-3.1690519 -0.0928308 0.0206810
-9.7080711 1.1121104 -0.1111400
8.0557100 -1.2885228 -0.3401546
11.8328164 -1.0425102 1.2826540
-4.4425455 2.3055157 -0.1666142
-0.6052985 2.2308396 -1.1851175
-5.9099158 1.7193246 1.1761248
5.2550402 0.8798181 0.3713147
-4.1254651 -0.3823787 -0.7885834
1.5988341 -1.0220653 -1.2340161
1.0140262 -0.3325582 0.5277046
-2.0803658 -0.2726236 -0.9767884
-4.1907135 -0.0798590 -0.2418980
0.0023367 -0.1084898 0.9800310
-2.8944323 0.2115060 0.4719462
2.5286842 1.6614213 -1.2869675
-3.1197282 3.2939510 -1.7719733
3.2675044 0.7586296 0.9098414
-6.5810486 -0.5094714 0.0217832
-8.2090687 0.3965828 -0.1035003
0.7888097 -1.2969903 0.4564361
-8.0288841 -0.6544826 -1.7474941
-4.4265639 -2.8076063 -1.4490956
-0.9660663 0.0012188 0.6275407
-4.1060106 -0.4289723 -1.0329992
2.4193336 0.3394903 -0.3294962
-0.8694654 0.7528187 0.0119195
-6.7386942 -2.8652262 0.1672382
0.5343544 0.5391727 1.7288593
-0.6001394 0.1915457 -1.0531064
-3.0804726 -1.4346086 -0.2863859
2.5768645 0.3025018 -0.8838206
2.5361497 0.3267081 1.4148947
0.3153646 -2.3396224 -1.5553198
3.7989466 -0.8787381 -0.9515567
0.9841500 1.1887510 0.6787740
10.6527495 0.1548357 1.2901042
-1.1127482 -1.6179643 0.0698945
7.0882586 -2.0808446 0.0575641
11.5366084 -0.3373479 1.0043655
0.7909233 0.7177226 -1.4459474
3.8447033 0.5195117 2.7412262
0.0428863 1.3332423 0.6105195
5.2705887 -0.9587809 -0.4644405
-7.0578016 0.4573415 -1.0222932
-12.6284158 -0.0194224 -0.6774237
-0.9497070 -0.6410682 -1.3626573
0.6741853 -0.9858863 1.2471974
-7.7529369 0.4594907 -2.2193869
8.3394394 -0.6869806 -0.0675731
-7.7120902 -2.4882482 -0.4818988
-4.8200934 -0.9887166 -0.0564008
1.6298543 1.1904718 1.0859072
3.2953484 -1.1104281 -1.0918417
8.2520032 1.7428943 -0.8080516
-1.1473430 -0.8816123 -0.3823746
2.8730512 -0.1584810 -0.2929969
-8.0170291 -0.2114933 -0.9938082
-2.0403814 -1.5072998 -0.6134804
6.9131283 -1.3500015 -1.5657899
-2.7912559 2.6079429 0.9771757
-1.2272313 -1.0105107 0.6430788
3.2425351 -1.6341734 1.6822346
2.7696644 1.5453870 0.0139683
-10.5804095 1.9002351 0.1202124
-5.0161796 0.1198612 0.9322863
7.2370630 0.0780347 1.2430905
-1.7927184 0.2876679 -0.4614044
4.1993943 2.2941767 -0.2482387
-5.1498987 0.5320295 -0.5148811
5.4790854 -0.9982559 -0.8608454
-5.4805880 -0.0738927 -0.2566889
4.9250160 1.4090512 0.2115417
-0.9405419 2.2793217 -0.4536110
-3.0167728 -1.2469757 -0.6063425
2.1440933 0.7403975 -0.5635388
-7.9314754 -0.5139862 2.0322189
-3.1443200 -1.3909872 0.3333828
-3.1271186 0.5107549 0.9513017
-5.7539155 -0.7698084 0.1211829
1.9488275 0.2169912 -0.1614737
-5.6210314 -0.4017468 -0.9796763
2.1560740 0.0691456 0.6275593
9.2952040 2.1249888 0.2263609
-2.9911878 0.4543654 -0.2636852
-7.3047473 -2.2512911 0.1178157
-9.5725867 1.1323698 1.6509161
2.1248195 -2.5114375 0.1892058
-6.5978512 -1.1676597 1.2218642
5.5666171 2.2246336 -0.1126683
-5.7756688 -0.4952071 -0.8858981
4.3561139 -0.9427889 -0.6454144
4.1185839 0.3815803 -0.4432339
-2.5147449 -0.5302805 -1.0887219
-5.7718912 0.8228022 -0.6597236
2.8208937 2.0413669 0.3481162
1.0418033 -2.7547779 0.1844275
0.9395051 -0.9938887 0.2201536
-4.3014570 0.8392057 0.2055559
-5.9992054 3.2585527 0.5247409
-6.1206459 -0.0725091 0.9388697
4.5711802 1.6602947 0.7942388
3.3508049 -2.9967610 -0.7550703
5.7019384 1.4258131 -1.2462413
0.5310267 0.3168603 -0.7616169
-4.4110055 0.1394222 -1.5227734
1.7893448 -2.3711705 -0.3009469
-5.7831102 0.6339738 -0.2225258
5.6581988 0.9902976 0.0289717
6.8201692 -2.3186632 -1.5144989
0.7048953 0.3811105 -1.2400670
1.0879114 -0.4111140 0.1462872
-7.9515392 -1.1364522 0.2644843
1.4980423 2.0324532 -0.1391460
9.3924657 1.6052357 -0.8442545
9.9638173 -0.8703001 2.1168076
0.5540930 -0.0404606 1.3680916
8.3009226 -2.0171617 0.9870967
-12.4973761 0.8953383 -1.3645184
0.0972874 3.4223286 0.6494148
-1.9457980 0.8905536 0.6676477
0.9891706 -1.1127371 -0.2332655
3.9430707 -1.9972270 -1.4599022
4.3746076 0.5998056 0.7843994
1.6950582 -1.0427000 -1.0569153
-2.4824611 0.3247600 2.6462555
-3.1028146 -1.9462386 1.8995821
-12.3677205 1.3910065 0.6651268
1.1078410 0.0840822 0.0083094
-2.4689774 1.0598615 0.8666068
-4.7507124 -2.4994718 1.8188853
2.9143881 0.7589273 -0.0020210
10.8901348 0.6910325 -0.0733066
7.4502535 -1.6745534 1.5207584
3.0392482 0.2867480 0.4437011
0.1236512 0.5871227 0.9852812
1.1161896 1.4745978 -0.1572281
4.0840659 -0.5707977 -1.3121261
-3.6363312 2.9033866 2.2115656
2.1411112 0.2129841 1.1046681
-6.7247486 -1.1685444 0.7052560
9.5401365 -1.0525107 0.1222523
7.7210618 -0.5660578 -0.6040249
0.0545377 0.0543478 -2.0738161
-1.3360557 1.3337570 -0.3332716
-6.5292047 -4.7140670 -1.0077187
-1.2088945 -0.3840765 0.0672767
1.1575366 -3.0412110 -0.7216841
5.4501288 1.1010765 -1.8858546
-9.1598040 1.7626226 -0.5515348
-2.6481041 1.6918439 -0.4160223
-11.6258481 -2.1221543 1.8513593
-8.8263997 0.2279249 0.4842140
-9.1348242 1.7749109 0.1416037
9.6951070 1.9654105 1.8907298
6.9411713 1.1689562 -0.0095299
2.5077391 -0.9239916 1.4956395
6.3270184 0.7969512 -0.0908723
-5.1650281 -0.0210953 0.6276367
-5.4874222 -1.0274393 -0.7216906
-3.4164256 -0.8901704 -0.5667387
1.4466480 -0.1340963 -0.5298624
-4.8109201 0.5700137 1.1204687
10.7938525 -0.4003214 1.7985971
5.0196369 1.3388509 -0.2742792
-1.3772594 0.8511564 -2.1826263
-0.0063484 2.4461201 0.0915179
0.5489903 0.9206064 0.9453235
-3.5272661 -1.3606901 0.3235235
2.3914772 -0.1382935 -1.6123655
-1.7845937 -0.3468150 -0.3698477
6.9872179 0.6721005 -0.8309894
-5.5661615 0.2002503 0.6490581
7.5336524 -1.1574562 -1.4459233
5.9445063 3.8235580 0.2419958
7.9504233 -1.2256532 2.5128913
6.7795563 -1.5435486 -0.1006525
-4.7633349 0.4146280 -0.1422369
1.4419295 -2.9563498 0.7375836
4.0477100 2.5341435 0.0269175
-4.5113107 1.2873590 -0.9940955
-0.8200037 -0.2942686 0.3407070
1.3488877 -1.1933759 -0.7381858
-3.7409799 -0.9351121 0.8673300
-5.2362948 0.7201380 -1.7539780
0.5595167 0.6898640 -0.6064697
14.4875425 -0.8781494 -0.5642109
6.4897637 -0.7047330 0.1389851
-2.0727333 -1.0004420 1.1516469
1.0967904 2.1698808 -0.4088451
5.4645312 1.9802854 -2.8578111
-4.1894865 -1.6904811 -1.6055205
1.8655986 1.2491076 0.8285276
-5.3938465 -1.9606164 -1.3022850
5.6845843 -0.3806324 0.5828057
0.1026435 0.1414442 1.3012888
-4.0750025 -0.2408023 0.7345394
-4.9159993 -0.3809253 -0.5540456
-0.4158528 0.1394161 0.1982454
-2.3213729 -1.8103196 0.8009044
1.6067434 0.5195744 -0.2828318
-7.0005917 -1.5725363 0.0461124
-6.5120267 2.0213922 0.1701163
4.1423046 -0.0267610 1.0533258
9.3884820 -0.6926981 0.8270415
0.6173668 -1.5265428 -0.6292293
-9.6608610 0.7162710 -0.0501053
10.8417526 0.1256019 1.5415506
13.6455043 1.8913947 0.6580715
6.6311309 0.1658878 0.1891414
-7.9477594 1.4796024 -0.2793544
-9.9761368 -1.6021350 0.2978928
0.5444993 -0.1783095 0.2626955
4.7751467 2.6498725 -0.1413199
-2.9638482 -0.3543837 0.3379057
-5.2484770 0.4123857 -1.9573298
4.1748351 1.2410888 0.7030369
2.3202074 -2.7580584 -1.3259287
-5.2739964 -1.7327195 -0.7250353
2.4046805 0.8761023 1.0290006
-3.5340017 0.1228034 0.7629376
3.8415894 -1.1833940 0.2004492
-3.1899214 1.8107410 1.7782990
-4.0812123 0.3232561 0.3894195
-12.0736657 -0.5188772 0.6692713
10.9963694 1.5382792 0.6250619
9.1286625 -0.5586797 -0.2889436
-14.0225348 1.4604405 -1.1159476
-5.8825678 0.8663197 -0.5791133
3.5142838 -1.1268946 -0.2531370
8.2458125 0.1938679 0.0627443
-1.1764531 -1.4330659 -1.2837846
-2.3897278 0.8977936 0.5166809
-5.5064819 1.4979442 0.0848200
-6.9801589 -0.3336988 -1.4253984
2.7377506 1.3486615 0.6952522
-4.8763912 1.0219988 -0.8186205
4.0900988 4.2112602 0.3272883
-0.6016983 -1.3870476 -1.0155317
3.4980331 -0.1818083 0.4100040
-8.5445369 2.3745013 -0.1766611
1.2864200 -2.6006597 -2.2487511
-0.4791643 0.9197185 0.5231637
-0.5400992 -1.9909795 1.3160565
2.6540984 1.4375120 1.0388430
-1.3026661 0.2159475 0.4012225
-2.4464838 2.4718086 0.8949823
1.9722229 0.7099248 -0.1768105
-3.9874881 -1.8429891 -1.4463085
-10.8657080 -0.8720935 -0.0204422
2.7822540 1.3945064 -0.1451745
-6.1889260 -0.3082639 -0.1741271
-3.9990695 0.1752288 0.4590572
3.7920848 -0.0252184 0.0141958
3.8231405 -0.5729438 -0.7373176
-4.6495784 1.4019123 0.1178246
-6.1410739 -0.6112695 1.9117948
-11.5139246 -0.5927819 -1.0513924
12.2848964 2.1541083 -1.7029174
4.5146124 -1.6787726 1.6035855
-6.0319482 -0.1953603 -1.4373893
-0.1579322 1.4903767 0.0184529
3.2608083 0.8504693 -0.0667993
7.5266172 -1.0169902 0.0427589
-1.6072449 0.1288171 -1.1894934
-9.6915355 -3.0388722 0.2338303
2.1521213 1.1849271 -0.0869757
-4.9490163 1.3779022 -0.4384216
-8.2287031 0.3831815 0.5628046
8.2211822 2.2525316 0.9855492
7.0786664 0.1691467 0.0020536
10.4355042 1.0361053 -1.2409777
-0.8653474 -1.7228683 0.6369202
9.3370196 -0.8530566 -0.7539352
-0.7230570 1.6034102 -1.4371997
2.7818191 0.5385680 -0.3077421
7.4559348 -1.4560478 -1.1795155
-0.0474497 0.6314953 1.8115563
-1.4024118 0.2486279 1.3822598
3.7283605 -0.7438085 -0.2299785
4.1115185 1.1384149 -1.7328503
-5.3976902 -2.9842702 0.9331951
3.5751372 0.9775690 0.1220483
-1.5675297 0.1951483 0.3760802
-5.7920691 -0.3868012 0.0880003
2.8892727 -0.1001260 -0.3950990
3.4850372 0.9445834 -0.7896257
-11.3966634 1.1703421 -0.6283300
-13.4769022 2.9162238 -0.2415889
5.0872702 2.4636200 0.5958202
9.6411940 0.5108973 0.6465302
-2.1719384 1.9967426 -1.0355173
13.2944012 -0.2581166 -0.9028117
-3.4047740 -0.5001170 0.5197776
-9.8008001 -0.6556580 -1.8216446
-6.3367257 2.2384854 -0.8777973
-2.6175056 1.7820757 -1.1515706
1.5442203 0.5753266 1.9766608
-5.9936697 0.9695795 0.4081822
8.9541620 0.6939543 -0.4915050
-6.2534480 -0.2448676 1.3384188
0.2814408 0.2847457 -0.1443592
0.3516918 -0.6147799 -1.4371389
-2.3156448 -1.7564826 2.0491803
1.1299607 -0.2248956 0.5067188
-0.9938364 -1.6903298 -0.1031155
-7.0302521 -0.9598478 -0.2447693
-4.2447747 1.7138086 0.0727486
5.1141486 -0.5909624 0.4991938
2.7045779 -0.6960988 0.3945884
2.5985947 -1.3223707 -1.0309881
-7.1130901 -0.8706080 -0.5588401
-3.7928685 -1.2208796 -2.0674523
9.9556491 -0.7693874 -0.0302499
6.9784091 3.1863368 -0.2561742
8.8037697 1.5758635 -1.5978014
4.8496609 -1.1737621 -0.1506123
2.4810824 0.0310302 0.3134863
9.6822122 1.0676730 0.5827167
-1.3412705 0.2362711 0.8046160
-9.2471757 -1.5523334 0.5419119
6.1392045 -0.3413549 -1.5522980
-0.4271513 0.3055907 1.4673554
8.8316276 -0.0045963 -0.8950702
-4.5764864 -1.1683509 -0.7644098
3.3492137 -1.3887593 1.0630318
-4.1497389 -0.3798463 0.9118572
-3.4678710 1.3738986 0.2136249
-0.3506330 3.2726460 0.9893660
-4.3430465 -0.0575051 0.0274094
-7.4559649 -0.3304470 1.7925481
1.2526839 1.1779646 0.2939054
-4.1476501 -0.3492701 -0.0261065
5.3961828 1.2675544 0.6343125
3.7861647 -0.7643412 0.0988616
5.4978823 0.8657121 -0.7431460
3.6633808 -1.1165800 0.8816451
4.3378223 2.0412582 -0.2666598
-7.2330896 0.2490346 -0.1236235
-0.7528408 0.2461529 -0.2958959
-0.9669044 0.4810820 -0.0337772
18.5513709 -0.3897001 -0.0283965
-6.5254264 -2.8195373 0.6697877
-4.2636912 -1.4183375 -1.2809679
2.9904283 -2.9395235 -0.6383072
-15.2850275 -0.7373667 -1.2432554
2.4382106 -2.3867573 -0.7308026
0.5982708 1.2821269 0.9660959
3.9537452 1.7761792 0.0213218
3.3857868 -3.4982792 0.8808273
-9.9575213 0.2911823 -1.9136573
7.8708156 -0.1973531 0.3362941
6.3279989 0.5121376 -1.3073720
-3.4920407 -1.6243292 -0.1670603
-4.7142614 0.0688159 -0.1580095
6.0203653 -0.4605614 0.5833991
-4.1996794 0.1510403 -0.3800481
-7.7126745 1.0674943 -1.0454957
4.9985158 0.8497798 0.5888681
3.1498347 -0.6154296 -0.0640294
-0.7707355 0.3539480 -1.9800288
-2.2278720 0.9322608 0.8122415
5.7145877 -0.9108463 1.1607479
1.6102364 -0.9065654 -0.0352262
5.2750431 0.4005857 0.0041416
-10.1689468 0.2836452 -0.5613754
4.7877476 -1.9740269 -1.1796054
-1.7140151 -0.7336470 -1.1369485
-3.5437551 0.6277266 1.3040092
4.4394317 -0.7148357 2.3795716
-4.0121067 -0.0304447 0.7374627
2.3020527 -2.5067901 -0.0524970
4.1892834 2.5326791 1.2279811
4.5419391 -1.0727045 0.2307581
-9.5636530 1.3001560 1.5049160
-2.1129284 -1.1150714 -0.7275411
-8.4491929 -1.2339318 0.6317343
-6.8455764 -0.2560662 -0.0877264
-5.1487883 2.4455434 -0.7498705
1.0353857 1.0295083 0.0532165
-0.1382711 0.5015641 1.0603914
2.3762595 -0.1517352 0.7364774
2.8256214 -2.6366012 -1.0424894
-12.0172285 -0.8604509 -1.2362828
7.1634130 2.5201949 0.4822315
7.2510201 -1.1122944 0.5233232
0.2399254 0.0520773 0.1234435
4.2403822 1.5261575 2.2764881
6.5613036 -0.3742145 -0.0478778
4.6452067 1.1333211 0.4244570
3.0837884 0.1834674 0.5783309
-0.2784320 0.8465852 -0.9695076
-1.0753100 0.0985742 -0.0420025
-0.6589827 -2.3021062 0.3393187
2.4255572 0.2840482 -0.0711093
3.0643326 0.7434459 -0.1484578
1.8584683 0.2824338 0.8468885
-1.5078660 2.8009782 -1.9600358
-3.3835697 0.1847263 0.6961531
8.1292963 0.1187115 1.5513818
-3.9206583 -1.2895303 0.3246259
-1.0752526 -0.6764675 0.7019336
13.4063967 0.9899954 1.2524669
1.8003518 0.6415596 0.3242558
-5.4934688 0.4552829 0.0847786
-6.8396914 -0.6012039 -0.9716206
2.5234704 -0.4298667 0.2899072
5.1646092 1.8108663 0.8593528
8.3076251 -1.3542169 0.1713719
-2.8946553 0.4860524 -0.6157100
3.2615076 1.9762856 -1.2113319
-3.3935349 1.2328083 0.2669153
5.0003882 -0.0157195 1.8154718
7.9055943 1.1268597 -0.5427247
1.8225493 1.2063981 -0.3084495
1.0546526 0.2204896 -0.0303897
1.0678129 -1.6776576 0.8647669
-12.5299477 -0.3984434 -0.0905205
-5.8247353 0.4266440 1.4556468
0.4573482 0.1355247 -0.7339516
-10.3604215 -0.2463889 -1.7756567
2.5202747 0.6650321 -0.9393787
-6.0394616 1.3861684 -1.0487564
8.9002225 0.4057583 0.6197410
2.1451084 1.7151341 -0.0788849


Let’s say we call all these new points scores and here’s how they look when are plotted onto a graph.

plot_ly(score_df, x = ~PC1, y = ~PC2, z = ~PC3) %>%
  add_markers(size= 0.5) %>%
  layout(scene = list(xaxis = list(title = 'PC1'),
                     yaxis = list(title = 'PC2', range= c(-20,20)),
                     zaxis = list(title = 'PC3', range= c(-20,20))))


As we saw on the scree plot however, 97.22% of the total variance is given by only two components, then maybe we don’t need to keep the third one.

In fact the contribution of PC3 in this case is minimal.


Score plot


ggplot(score_df, aes(PC1,PC2))+geom_point(color='cornflowerblue', size = 1, shape= 1)+
  ylim(-10,10)+
  theme_classic()+
  xlab(paste('PC1 - ', eig_df1$Var[1]))+
  ylab(paste('PC2 - ', eig_df1$Var[2]))


Loading plot


loading_vectors = t(loading_vectors) %>% data.frame()

ggplot(loading_vectors, aes(P1,P2))+geom_point(color='cornflowerblue', size = 1, shape= 1)+
  ylim(-2,2)+
  xlim(-5,5)+
  theme_bw()+
  geom_segment(aes(xend=0,yend=0), alpha= 1, color= 'darkred')+
  xlab(paste('PC1 - ', eig_df1$Var[1]))+
  ylab(paste('PC2 - ', eig_df1$Var[2]))+
  geom_label(label= colnames(df), color='black', size=3, nudge_y = 0.3, fontface='bold')+
  geom_vline(xintercept= 0, linetype="dashed", alpha = 0.3)+
  geom_hline(yintercept= 0, linetype="dashed", alpha = 0.3)


Biplot


ggplot(loading_vectors, aes(P1,P2))+
  geom_point(data=score_df, aes(PC1,PC2),color='cornflowerblue', size = 1, shape=1)+
  geom_point(color='white')+
  ylim(-10,10)+
  geom_segment(aes(xend=0,yend=0), alpha= 1, color='darkred')+
  xlab(paste('PC1 - ', eig_df1$Var[1]))+
  ylab(paste('PC2 - ', eig_df1$Var[2]))+
  geom_label(label= colnames(df), color='black', size=3, nudge_y = 0.3, fontface='bold')+
  theme_bw()+
    geom_vline(xintercept= 0, linetype="dashed", alpha = 0.3)+
  geom_hline(yintercept= 0, linetype="dashed", alpha = 0.3)


As we see, most of the variation is carried by \(X_1\) and \(X_2\) and they’re clearly correlated one to each other.