R语言 因子附加变量标绘与标记子集

bpzcxfmw  于 2023-01-28  发布在  其他
关注(0)|答案(1)|浏览(115)

我已经在R中使用prcomp运行了一个PCA,我试图生成一个变量图,该变量图具有1)变量子集(箭头)与其余变量的颜色(黑色)不同,2)在绘图之前对这些变量进行排序,以便黑色箭头不会被任何其他箭头覆盖,3)用它们的TUXXXX编号标记黑色箭头。
以下是我的数据的截断版本:

structure(list(sdev = c(21.7106794138444, 15.6885074594869, 11.9124316528111, 
10.155277241318, 9.31528828036412, 7.56876266263865, 7.19938201515987, 
5.81620977435434, 5.00785424840699, 4.57228787327195, 4.51525494575488, 
3.20601607034873, 2.91477640215067, 2.48737967730048, 2.13230488376163, 
1.74923754200417, 1.32745772948038, 1.27373216417502, 0.924437474777366, 
0.749074623004602, 2.499709597053e-15), rotation = structure(c(-0.0710441966458092, 
0.091894514828866, -0.0892433537986534, -0.269473709517009, -0.270455466278075, 
0.217492458575054, 0.104541973199297, 0.198858094257877, 0.0222680112919805, 
-0.220704163347643, -0.0144913885562279, 0.191255085890651, -0.0639203495167002, 
0.156262929972648, 0.184067836594737, -0.221797618857792, 0.152932751853774, 
0.218733634550932, 0.213989867048259, -0.219209176045661, 0.162232843055052, 
-0.182649403408074, 0.0732706002149817, -0.0636694683826245, 
0.197950156891487, -0.201332798849071, -0.0908133550739104, 0.204561640782066, 
0.144543461720936, 0.128722984809536, 0.152014925749702, -0.219186163224382, 
0.137427869376807, -0.0385728465064452, -0.210836096156869, 0.295086522896984, 
0.0791956927556792, 0.154250304318938, 0.212537035577304, 0.165554637810987, 
0.0559168852882808, 0.0389301896007549, 8.50109782205011e-06, 
0.0386719091643949, -0.223181316780788, 0.0201295766763838, -0.0993945550528442, 
-0.0797657364873552, 0.290392094157839, -0.210104310439075, 0.190507620860241, 
0.288216604566037, -0.128091623622577, 0.0523741236254804, 0.165286635170839, 
0.26567738477018, 0.067304658063138, -0.185395359345644, -0.0824392053628523, 
0.0232331903282599, 0.206712718290849, -0.0599454190622519, 0.0694655529225049, 
0.27934713843206, 0.120105146108152, 0.276987279291797, 0.137068573563571, 
0.290227550805898, 0.0299855300238849, -0.048045392789825, 0.217209812823655, 
-0.245207498414819, -0.0969050397538762, 0.0152958298727508, 
0.0611874790392221, 0.244015616675892, -0.341439467152496, -0.0574074669754257, 
-0.187473105527714, 0.0859725296785313, -0.230526618631008, 0.164238788534203, 
-0.422116092865793, -0.0847447867791298, 0.0984005915083912, 
0.0400031956936472, -0.0768787993932683, -0.127305543959199, 
0.174417860300221, 0.00642366483942508, -0.0644270895895563, 
-0.0445557418009, -0.206781215165792, -0.398796252833277, 0.198729650467593, 
0.0351312161529938, -0.149474677035792, -0.0671760700655275, 
-0.0776573448858521, -0.0276268199179851, -0.0622850132226139, 
-0.0133848915206553, -0.0412751078511757, -0.196695235499305, 
0.035533391699955, -0.0471461480863407, -0.471887698745297, 0.385807939659813, 
-0.0521508210675749, -0.106054753553622, -0.0520098951237357, 
-0.328301752147492, -0.0885218905714762, -0.392528395483506, 
-0.0535243088811493, -0.0012232141956296, -0.143968515821013, 
0.110020791115645, 0.105789408005642, -0.0173550741395983, -0.0754711706175302, 
0.105789800532602, 0.035696880367874, -0.0235700328573188, -0.086664772131814, 
0.140659513401983, -0.147738109860937, 0.158253547879328, 0.096508294839766, 
-0.0405645836586841, -0.0308947063294566, 0.196563611460491, 
-0.163272613036823, 0.102159062108236, -0.242801481572191, 0.100060947435785, 
-0.122408620775568, 0.0879253395566385, 0.0964448760240853, -0.10574290240921, 
0.473324985332234, 0.237791221156891, 0.121312056042028, -0.0156952213549262, 
-0.0509545579371996, -0.188663582956394, -0.0296470996543493, 
0.259217775431442, -0.151966417414955, -0.0246227447960926, 0.412107323913548, 
0.135772975480753, -0.0902168853917747, -0.0478519874649824, 
-0.0293395316078502, 0.036873372126565, -0.0600803315985544, 
0.0951569802806819, -0.174539345831377, -0.0567399129758035, 
-0.0522218071944251, -0.0208963041931566, 0.15376867866167, -0.0906491458699936, 
-0.13257887196968, -0.0137277293203767, -0.329880055323168, -0.227898895128165, 
-0.0402178711138279, -0.191724054954671, -0.0457418642155951, 
-0.113122585201102, -0.0523451728177034, -0.0619052030873901, 
-0.232037793152732, -0.286608825250971, -0.337575786471338, -0.106930203013502, 
-0.0488020861881439, -0.0342694484533206, -0.316010730818033, 
-0.138362452107825, 0.000204654351180751, 0.34062110315846, -0.0174472565351551, 
0.321216705099307, 0.109402271713093, -0.195953316697484, 0.106147314965255, 
0.0965509971711528, -0.0619150877056984, 0.0823900429544073, 
0.107331603831664, -0.196505739977505, -0.106531330626324, 0.083316396319378, 
-0.0150328553267955, -0.131557865292901, -0.197676924192316, 
-0.302438247351333, 0.0850937235677142, -0.0588088540505814, 
-0.0137660099545295, 0.0981614485249126, 0.064387690302654, 0.0870877447014138, 
0.115369776587117, 0.0743160202050587, -0.302341999379974, 0.0990657432090211, 
-0.109416851119016, 0.0566207941620112, -0.563376445425201, 0.022987878311214, 
0.00914995477596945, -0.0698458973541682, -0.339551294424273, 
0.328653723240687, -0.311621856766325, 0.0451475830297207, 0.0486778657760599, 
-0.203890915518391, -0.00733314039012801, 0.0302380986964549, 
-0.187740946530342, 0.107505967223115, 0.0112058761308914, 0.0124189091072754, 
-0.0946013978939246, -0.0108516955206006, -0.0224544300789198, 
-0.200447923165361, 0.00227210575436315, -0.0230219082173417, 
-0.115276809069961, 0.113599893064251, 0.0547021334782484, 0.0750295713780988, 
0.0318176533771422, 0.270756307602172, 0.0158888930662066, -0.0321100878211108, 
0.0137635276916354, 0.285629078757821, -0.0707869220022327, -0.196194173921016, 
0.0691894805409008, 0.196425060869134, 0.0609662656649608, 0.0112726648905893, 
0.0763548314916228, -0.0203154117969338, -0.154183879477363, 
-0.263435512251247, 0.0904584427059006, 0.443081105454767, 0.145760707944433, 
-0.124076693641366, -0.00926033658765893, 0.322008337751576, 
0.038976848601001, -0.00243771729397693, 0.0682300992336678, 
0.101208051579165, -0.0044801862648156, -0.0288479608546419, 
0.338293188340527, -0.148520145256712, -0.114001067101895, 0.0429068793268258, 
-0.0808048267081677, 0.0147906601414549, 0.00024012812721683, 
-0.0245592922986743, 0.26189600932665, 0.0089069926197661, 0.102640316156789, 
0.0293398861736338, 0.461748240785653, 0.0268162505216955, -0.0262617915066989, 
0.128477574136056, 0.304269602566599, -0.00833894425455883, 0.0183612622798514, 
-0.0694598653855358, 0.143473468921974, 0.494741840190451, 0.11710470731812, 
0.0938975501248067, -0.111819356177393, 0.074487393087207, -0.236744656433776, 
-0.00888263838265717, -0.0411308668141714, -0.0205247425377322, 
0.00682064532990936, -0.0657589971316789, -0.0854778766938379, 
-0.0446898232128541, 0.0595158665026168, -0.164975323219787, 
-0.21297106776461, -0.24328292167101, -0.0421999896796148, -0.0454152302659223, 
0.536798625888851, -0.107184764029374, -0.134710620292912, -0.0486878301757869, 
0.0112145455041351, -0.0888773206829193, -0.0231311387150055, 
0.160224502964451, 0.116642580196556, 0.132842779999407, 0.0815222556677455, 
0.0846715273158058, -0.168358316697627, -0.141086214309714, -0.0812000194350307, 
0.108662664398591, -0.0391921007274459, -0.231315089883372, 0.25650378734853, 
-0.0459946623780035, -0.366253502200094, 0.0485143397750607, 
0.0417032700002287, -0.133038776710167, -0.230298287475923, 0.0369759420468897, 
-0.00906710613565646, 0.0342935061381997, -0.273232725280753, 
0.0602621389601039, 0.206808600842623, -0.32050527301245, 0.0622454407253566, 
-0.0606525149750042, -0.0660628546307464, -0.038482743495315, 
-0.198081930190034, -0.0732284456644516, 0.405606839140943, 0.0459681574877996, 
-0.0809991829793473, -0.0121246261443008, -0.326485629157016, 
0.0750251561011149, -0.0511696428776832, -0.0776271119484428, 
0.0114894367280979, 0.014021492503364, 0.118849898460583, -0.0350044617639092, 
0.0269961041673681, 0.239744113644073, -0.233879279575839, -0.115473220682409, 
-0.139126309932733, 0.11002945246376, -0.0830577400425309, -0.0642289884705754, 
-0.0817307298240943, 0.0291046627888711, -0.0466920006759583, 
0.256672775663942, -0.0137954035992047, 0.17957481447807, -0.0303657675236596, 
0.518263963411537, 0.344005787563606, -0.0655688570898937, -0.0265294401946153, 
-0.0263107898868621, 0.289506920843548, 0.118475732210224, 0.053567958881615, 
0.146877133183997, -0.0549414997788912, 0.143851895777107, 0.0428308701652828, 
-0.348959761946987, -0.189096210288467, -0.00385035890156567, 
0.150120708161381, 0.0607203081654835, 0.000166036942981724, 
-0.0397011322296128, 0.0239760961564877, -0.00913095901818713, 
-0.136862964262375, 0.102111106897839, 0.0687169707815706, 0.239013538410316, 
-0.39892902681439, -0.197510750116376, 0.0499804963638917, 0.128640553281137, 
0.110040614593457, -0.0490679379082568, -0.234025706976098, 0.157764576030734, 
0.0571664700394519, -0.074307378291659, -0.231764546118876, 0.565447067892318, 
-0.21480675567977, 0.0854469138131175, -0.0976097155414531, 0.160801495571792, 
-0.0624041394929365, -0.0127140410117323, 0.196633195933416, 
0.0340211274197625, 0.0195595932420065, 0.0964345475133984, -0.174817763577626, 
0.118153342593374, 0.225094093283825, 0.0276798513722757, -0.39244132040106, 
0.0738620568768489, 0.027031867335908, 0.0584738274201628, 0.00728266929277696, 
-0.200928813049723, 0.100479151028423, 0.217133686900663, 0.152350478604359, 
0.0798552081200005, 0.00566909653422267, 0.15071802028838, -0.0828967915619975, 
0.0689991484295119, 0.118221935665031, 0.418906970577945, 0.161468821548893, 
-0.0443917405359232, 0.127346300562372, 0.0854487046042784, 0.0086243432217815, 
0.0186528057922736, 0.143224492276055, -0.113522100459258, 0.365748845830972, 
-0.353026210924788, 0.0928434654809545, -0.217256921150109, 0.0926292235900054, 
-0.0360081503134767, -0.0761247497474667, 0.0137710983238269, 
0.135604749840715, -0.366785665744512, 0.174928851514231, 0.0364877873595186, 
0.0808239023932249, 0.057715463934493, 0.103601691734105, -0.109666857605533, 
0.38393023627746, -0.117248332196572, 0.134270206368149, 0.0580313640704774, 
0.0649484539445183, 0.215353645432973, 0.0977108936702795, 0.16612143102929, 
0.152770485581267, -0.0516344648811396, -0.0620940862015108, 
0.114473317921704, -0.0383202829927206, 0.0820220075422196, 0.0556449561108403, 
0.0053103511581772, 0.141569483443786, 0.264761186392854, 0.231379833347928, 
-0.186458908266326, -0.280612868599116, -0.0134977078164976, 
-0.190682413873154, 0.103622962625572, 0.048589128670959, 0.189228510250879, 
-0.267141675131746, 0.24968486643315, 0.000515248155113446, 0.0518714761513495, 
-0.0123619986636973, -0.0400774164248301, 0.14696585867848, 0.00893605318819822, 
-0.115310054522583, 0.0730556770081751, -0.0415182843892857, 
-0.100197819082248, 0.366565649542296, -0.280217314004845, 0.0742548639941826, 
-0.0598573375691124, 0.0773367591528449, 0.00440008401952238, 
-0.133823453930746, 0.0129306082883093, 0.249237874757721, 0.178566150191566, 
0.0236542331383419, -0.121983928027758, -0.407639692892733, 0.105625218150781, 
0.0606170741355181, -0.205658012407281, 0.198411895098939, 0.314706002474467, 
-0.0699572649574542, -0.256054196724344, -0.0597932960838045, 
0.12552805883941, -0.0738282459049305, -0.270044343022259, -0.241030766471284, 
0.101198016298546, 0.207020228203116, -0.105134856921501, -0.0677078010226698, 
0.0597983546937891, -0.181549492585234, -0.0707807644693492, 
-0.242992185702685, -0.164512180143508, 0.0345701932987703, -0.0663154906257285, 
0.302765631613708, 0.118224308922645, 0.0673423264385151, 0.417740310978627, 
0.111554431260226, 0.16022442648127, -0.25635936207313, -0.35265959952747, 
0.0429263261414316, 0.140480243375922, -0.130382613873709, -0.0446328161712632, 
0.120679204177165, 0.100894280068327, 0.102396715497024, 0.292226072514004, 
0.0170232777619504, -0.0854499461046589, 0.150649869168952, 0.054457847943396, 
-0.0755734422376126, -0.0485946974863497, -0.214957242429833, 
-0.19078567042026, -0.265677083691519, 0.11169177584997, -0.0546945656068388, 
-0.133918556644411, -0.0815433043760734, 0.0419081230722499, 
-0.119806690064691, -0.129001645490559, 0.164330559962565, -0.494999436348284, 
-0.0104711534954494, -0.151933262861035, -0.0616048245349729, 
0.0510091356535412, -0.15286661063535, 0.286795952380893, -0.00227878893487643, 
-0.121875652782209, -0.0463279998907995, -0.08440989195395, 0.0161463685432679, 
0.283239464786081, -0.0997334879966379, -0.107077349937415, 0.0797083319878824, 
-0.023817698507559, 0.0308411589066249, -0.33639040110823, -0.22283646210506, 
-0.0472382156514798, -0.0383954704026199, -0.279873414947505, 
-0.110928067466998, 0.0224738031700519, -0.240448693328791, -0.0234165327843327, 
-0.164995870598194, 0.0704836439566211, -0.0341351365684308, 
0.253109207656731, 0.0986224720533927, 0.0788051554263656, 0.0348921204456385, 
0.179396594950779, 0.183681460022634, 0.165162541829685, -0.131056895026594, 
-0.043658366747374, -0.164919051972395, 0.000438005379084683, 
-0.203731301273092, 0.156795003278361, 0.147134057978626, 0.0674666995224469, 
0.0387098969653998, 0.0780676163151537, -0.020902824954741, 0.0863172379869736, 
0.0254543096586073, 0.221894385139484, 0.605679699321179, 0.00510726652451246, 
0.0122597366937914, -0.177909018628657, 0.112879199323714, 0.00722763837901889, 
-0.226515396833189, -0.179516219763039, 0.0427914553668244, -0.301499857490821, 
0.07077374887633, 0.0684478824696676, 0.109600278015023, -0.246938356324243, 
0.0361050298642269, -0.273671368850468, 0.0361740234532937, -0.0379154357295922, 
-0.140858482198813, -0.210557939874765, -0.183530140411959, -0.170246755949232, 
-0.153695213839514, 0.197257212733899, 0.176328880404244, 0.267335680405474, 
0.0108203611164604, 0.420718967278865, 0.0610513794750232, -0.0695142190235678, 
-0.0211301631659223, -0.109598478540236, 0.0168455051311258, 
0.0297211637285332, 0.0641419705460361, 0.196768178957862, -0.101223881022882, 
0.156790420489079, -0.248396712859248, -0.0324362090799154, 0.116497846273851, 
0.206631759837322, -0.26949738606709, 0.0523825016986687, 0.273991705979531, 
-0.211717836239047, 0.343025575540513, 0.123225187210276, -0.130175293604759, 
0.383814266477628, -0.0425846714760806, -0.120958839664608, -0.222129739206683, 
0.0129931836329733, 0.144776049791581, -0.162517014653887, -0.0859042045925978, 
-0.181054333724447, 0.0216585016380889, -0.0923250223535876, 
-0.103640362754872, -0.223956862384563, 0.213416939275391, -0.21381164272001, 
-0.235056303853187, -0.0630316125230271, -0.105100763021652, 
-0.0360147146171049, -0.0709796908578211, 0.113552355258653, 
-0.00724023466942227, -0.0325253318186826, -0.0460572605581843, 
0.362655177721721, -0.102542875980008, -0.0801797191999012, 0.107198034030814, 
0.183373945987406, 0.0309647928318137, -0.236970374446373, 0.0520664942182686, 
-0.0402703424381589, 0.0504291632173252, -0.158130484290709, 
-0.112283134517499, -0.300637215703608, -0.231320162708774, 0.0785169224262154, 
0.23958352054759, 0.426485005426312, -0.0815406319434192, 0.00340039424643938, 
-0.0375428689912434, 0.33351700972973, -0.0800149829632403, 0.140498383489292, 
0.167368656035586, -0.0844117015281891, 0.0785085162751926, 0.0489486062002369, 
-0.0561511863757523, 0.234387154088994, 0.0481142285230063, 0.0705808780719704, 
0.221875388986379, -0.148031374880166, -0.0894717302805895, 0.231743942045981, 
-0.210616362796393, -0.0812013243962482, -0.185771800435443, 
-0.0438135376399639, 0.218374086144347, 0.121623152294345, -0.170058260806661
), .Dim = c(35L, 21L), .Dimnames = list(c("TU35976", "TU38792", 
"TU35975", "TU4897", "TU9262", "TU18312", "TU38793", "TU30299", 
"TU38794", "TU16422", "TU32068", "TU12311", "TU18325", "TU22117", 
"TU20746", "TU19660", "TU41790", "TU43092", "TU18309", "TU19659", 
"TU16277", "TU34798", "TU10953", "TU18317", "TU18307", "TU9186", 
"TU17864", "TU15658", "TU14030", "TU15669", "TU9890", "TU33617", 
"TU16279", "TU27042", "TU17167"), c("PC1", "PC2", "PC3", "PC4", 
"PC5", "PC6", "PC7", "PC8", "PC9", "PC10", "PC11", "PC12", "PC13", 
"PC14", "PC15", "PC16", "PC17", "PC18", "PC19", "PC20", "PC21"
))), center = c(TU35976 = 6.61238491831215, TU38792 = 10.2487864648085, 
TU35975 = 7.41959195648095, TU4897 = 10.9311685931669, TU9262 = 11.0918083964267, 
TU18312 = 11.7076238975148, TU38793 = 9.74398564779285, TU30299 = 12.892315214803, 
TU38794 = 9.54139631961704, TU16422 = 12.3329627148834, TU32068 = 7.97610519995008, 
TU12311 = 10.3617106799956, TU18325 = 7.59060411317826, TU22117 = 9.03799676912002, 
TU20746 = 9.178102720165, TU19660 = 9.87502757868133, TU41790 = 8.9943466756264, 
TU43092 = 10.9585816938684, TU18309 = 10.6298994150062, TU19659 = 10.3934726050624, 
TU16277 = 8.32556725898017, TU34798 = 7.02103110645297, TU10953 = 7.01860382462013, 
TU18317 = 7.36244270525821, TU18307 = 11.3778296252987, TU9186 = 10.7024172065364, 
TU17864 = 8.2903853475227, TU15658 = 6.58819311715545, TU14030 = 8.134641008701, 
TU15669 = 7.01449935590416, TU9890 = 8.13988320730633, TU33617 = 10.6809972208427, 
TU16279 = 7.9614057227348, TU27042 = 7.34221912393268, TU17167 = 11.2592403834747
), scale = FALSE, x = structure(c(24.4897868475554, 12.4416010164283, 
12.3200413661576, 6.91612686789472, 30.5655787046573, 33.5373707608136, 
6.7521417841798, 31.2938791704631, 29.0635289584208, -23.3354523484558, 
-15.6229701200559, 6.43010789907339, -24.9147092475567, -31.0094950116289, 
-28.4137928961069, -21.5926413362042, -3.97585196983663, -20.8563124842282, 
-0.593920033332157, -3.64572299218967, -19.8492949360489, -9.96693484414473, 
-23.5449684594658, -18.996265716943, -23.7811581634436, 3.93738430048, 
9.37353195322868, -19.423648038774, 7.87596964384287, -3.13661328005585, 
-7.09016527838172, 3.71259770410569, 23.247076153704, -2.03249135782906, 
-3.64325919770972, -6.94450353973124, 7.55306940052889, 31.346240781817, 
-3.48931847017886, 29.4056029647248, 12.4861765573918, -6.8883231131661, 
-6.8786118382072, 15.8325477899497, 15.3870141654559, -11.3237572934353, 
-4.49560209730399, 1.115062768913, -20.2141393532659, 9.76193925462921, 
-1.15731242202584, 6.22677163564855, 14.431909276018, -13.4812455995592, 
-9.58096578254001, -10.0824168036361, -10.1417065317313, 6.11246229818054, 
-4.84525793168699, 14.9352609583166, 16.1272133946181, -17.0836840355263, 
9.35451814718846, -6.63382933222961, 5.79244304277846, 7.73028939318989, 
-6.00113726185851, -8.57575275731579, -6.70414747438031, 11.0021295692077, 
7.62205208005063, -6.03281844054887, -1.59444275830952, -7.70227835025931, 
-6.4184560830441, -12.3696585650364, 1.42826497938592, 8.28315195406988, 
-13.8464231033084, -6.95076374785849, 5.03179685038719, 16.6482451825695, 
25.4557137741208, -6.16437895161065, -0.188023057317339, 3.51919999146276, 
-3.06021456766217, 12.7300628490286, 0.340348842202129, -4.18342952961951, 
9.91999265542052, -6.2673275997563, -6.19445525060979, -4.89432563084305, 
13.3155996092707, -17.5672684031691, -11.0570104414685, -10.1512940397755, 
-2.83422832939901, 11.2933772476208, 18.438427176494, -10.6101681685668, 
2.08048057352476, 5.50745324586983, -0.13719717270706, -8.9884667602456, 
-2.05928444313446, -0.305773393272364, 4.86554463593651, 3.76285186780856, 
6.3828926870771, -9.3655246100571, 7.43651870615979, -1.67082019758757, 
10.9895599029683, -13.9919213196391, -7.47010213808747, -5.18316808251628, 
3.09935494483666, 0.0636557688816208, -1.54858827353552, 5.76445544260896, 
-7.0244817763404, -6.91485718432494, 6.12343812013661, 16.0347161023267, 
-6.04452306419056, 0.503323158087318, 1.11905480618314, -3.32310396567328, 
3.1274151532053, -1.0139189902977, -2.77210893619864, 5.73300675328722, 
-2.20016077060467, 6.88733384115661, 9.29615931028018, 7.89283806484175, 
-0.0231784873612931, -13.6472361241707, 8.57047305874539, 9.82836851225084, 
-12.0042402273719, -9.50514572716062, -7.91330903314343, 8.52172081325052, 
-3.03276814511544, -8.49580406093405, -2.33842120098311, -0.32804627167184, 
-3.21259723306479, 11.1229701308803, 0.598883041283415, 5.30460923308376, 
1.00174438392002, -1.97289932239362, -10.2991918599681, -3.87835358264123, 
-2.25659286308468, -0.166946108131337, -4.78949081440092, 3.19183354598423, 
4.8383258847991, 0.890821633270318, 14.2375666218091, -6.1498396420083, 
0.00274092818159516, 2.69868755607018, -6.72994548395586, -2.87563409646143, 
6.39162216555694, -1.86430696261611, 1.49349337044142, -0.729377873822674, 
3.91976580406387, -4.55169784656593, 4.01470477896383, 9.45815735561592, 
3.87143750044459, 2.8485319829077, -3.54554995799273, 2.1592779575771, 
-10.2265407210419, -2.57734842434015, 3.85728531842232, 3.91861430861892, 
-6.08938026261039, 2.90775931244037, -5.65086822564584, -7.43442226552497, 
-0.28834246695089, 4.46777893840091, 1.61867182502613, -1.24379496084697, 
3.09330484415506, 4.6129428255061, 4.21327794340158, -2.73480960596815, 
-1.34501116390485, -4.95417459779772, -1.50853746838879, 4.27315750243976, 
5.82184171959861, -3.417633941994, 9.09574374372561, -2.51371486672449, 
-5.3839624715871, 4.02549123440248, -4.25205519103745, -6.14575157593085, 
3.39653326861517, 2.02195972923006, 0.737129651195039, -3.82060608464456, 
-5.8916049884138, -1.48103866101421, -4.15462594283813, 2.85762680978641, 
8.01848063520863, -0.33318325779775, -4.11692676832453, -3.14609004733945, 
-3.87716607273847, 2.15863837910027, 5.89633795035078, 6.78408908767204, 
5.31335299395838, 2.26271596099398, -6.04004269690954, 0.66943773718038, 
-7.25501768327073, -1.85352333808763, 0.881321761644734, -3.37300816578494, 
1.72336449307423, -1.12738959732561, -1.00315691989581, 1.22856047955961, 
-5.49078567616185, 7.36566150881169, 1.5098504796481, -4.40047569826546, 
1.27392003732061, -1.32431052177641, -3.49056795319117, -1.81317399652518, 
4.21470358856118, -3.35477920804357, 0.76847614798403, 4.53289945581295, 
1.08860795433414, 2.64380516830634, -3.5282442958868, 0.44695028657078, 
6.40236529107031, 1.40990912221294, -0.646731159533322, -0.886819655598922, 
-0.75355529529178, -3.22681748481868, 1.14443040171423, -1.01721629940821, 
-1.91406441412825, 2.79795257160194, 1.42125707801834, -3.78513731974819, 
5.22015934186783, -3.11038146921718, 4.2502371748613, -2.23573426796635, 
1.2890326250481, -3.2044887828359, -0.0731034485321765, 1.00689042463065, 
3.10770789167095, 0.653717111815948, 2.0046773828616, -5.05502285926648, 
0.670269628945531, -0.0735066911646989, 0.567378074513561, -4.12216401435608, 
-1.34361612453716, -2.31031886740573, 4.81653041064168, 0.0225272846463933, 
-2.29390683891735, -3.34883149458521, 1.62567523985947, 1.46413728406672, 
2.19861127383831, -2.2813563892377, 1.48246659900362, 1.20813467297598, 
4.19016124903691, -3.8965814643401, 3.56184752348759, -1.3878373295987, 
1.21458977444305, -0.654562661488364, 0.95632241225039, -1.55232118983605, 
-2.44238882925152, 1.13264815277383, -1.78862294430386, 0.991256365490394, 
-3.88951966260596, 0.202107196565979, 0.551090451321218, 2.66348016156913, 
-0.854309938495967, -0.232716071672556, 0.851674118269924, -0.985653498045505, 
1.36933618443016, -0.586856938122795, -4.1119301713715, 1.0178280457984, 
0.338189042904915, -3.94726389810293, 1.81377558126379, 1.58372328030388, 
1.72308989346244, 2.19193280022478, -1.61256462530986, 1.96795000825428, 
-0.618527965915178, 0.0756192601567935, -0.659358025397941, 0.0429550715360451, 
-0.381324238450748, -0.652905276182954, 0.170764900323459, -0.641706794178386, 
-0.0221222785810836, 2.30873232738461, 1.27649223277723, 0.0239704300112933, 
1.61258498499148, -2.05589657580369, 0.0265571467877399, 1.25029287962319, 
-0.571431828720408, -1.73619374916576, -0.0382088144200337, -0.321239936961026, 
-0.611330806517872, -2.02090803294801, 3.14396363436869, -1.10262030332252, 
-1.04168768271449, 0.37429480503427, 0.104514606536275, -0.478767952336214, 
-0.192546893385304, 2.1627661920923, 0.195395664072845, -0.782469508379251, 
2.08546244595102, -0.0517755897340584, -2.39907743930418, -0.211807017194547, 
1.71381905614487, 0.83072521628824, -1.60469551897193, 0.245800797687136, 
-1.46819802906202, 0.849407708022543, 0.917523253251796, -1.60319562494994, 
1.89391093257302, 0.378604048008997, 0.14292959825461, -0.126413703865446, 
-1.54645185235878, -0.749700454486876, -0.0658077625468692, 1.55140944467166, 
0.302322289091245, 0.458890126236888, -0.788003883776506, -1.8522098865949, 
-0.303600234099745, -0.869244048674518, 2.09285131170145, 1.13594169034256, 
0.00257581110260907, 1.28821287823238, -0.603719944771219, -0.0929817189825319, 
0.646083878133434, -0.997976432253114, -0.0887921104756663, -0.252335674196718, 
0.885171983511843, -0.455664633944459, -0.080944547822266, -1.11153038212543, 
0.684953529364659, 0.00107091275654292, -0.0523472212020604, 
-0.722665903230519, 0.112695429436832, -0.431332703576418, 2.28632079906497, 
0.389976510624337, -0.672770348738164, -0.710872748519771, 1.11097033239239, 
-0.117525841496901, -0.38659967304807, -0.311519238694312, -0.58769206070627, 
0.880912821150173, -0.223180949008615, -0.0563287542495416, 0.677577799103385, 
0.174786309548343, -0.486054451272286, -0.875421020334039, -1.99840144432528e-15, 
-2.19269047363468e-15, -2.80331313717852e-15, 3.39658856596259e-15, 
4.44089209850063e-16, 4.44089209850063e-16, -2.44249065417534e-15, 
1.11022302462516e-15, -6.66133814775094e-16, -4.44089209850063e-15, 
-3.5527136788005e-15, -2.33146835171283e-15, -6.43929354282591e-15, 
2.44249065417534e-15, -1.4432899320127e-15, -2.19269047363468e-15, 
1.0547118733939e-15, -1.11022302462516e-15, -9.99200722162641e-16, 
1.33226762955019e-15, -1.55431223447522e-15), .Dim = c(21L, 21L
), .Dimnames = list(c("EDA_01", "EDA_02", "EDA_03", "EDA_04", 
"EDA_05", "EDA_06", "EDA_07", "EDA_08", "EDA_09", "NDA_01", "NDA_02", 
"NDA_03", "NDA_04", "NDA_05", "NDA_06", "NDA_08", "NDA_09", "NDA_10", 
"NDA_11", "NDA_12", "NDA_13"), c("PC1", "PC2", "PC3", "PC4", 
"PC5", "PC6", "PC7", "PC8", "PC9", "PC10", "PC11", "PC12", "PC13", 
"PC14", "PC15", "PC16", "PC17", "PC18", "PC19", "PC20", "PC21"
)))), class = "prcomp")

下面是重现此问题的最小代码:

library(factoextra)
library(tidyverse)

# create a named factor for coding the coloration of the variables in the plot
markers <- facto_summarize(pca,
                           element = "var",
                           result = "contrib",
                           axes = c(1, 2)) %>%
  mutate(candidate = ifelse(name == "TU35976" | name == "TU18317" | name == "TU12311" | name == "TU3565" | name == "TU9890" | name == "TU18316", "1", "0")) %>%
  select(name, candidate)

markers_vec <- as.factor(markers$candidate) 
names(markers_vec) <- markers$name

(var_cluster_PC12 <- fviz_pca_var(pca,
                                  col.var = markers_vec,
                                  axes = c(1,2),
                                  select.var = list(contrib = 200),
                                  palette = c(
                                    "grey90",
                                    "black"),
                                  label = "none",
                                  ) +
    theme_bw() 
)

生成此图:

这张图并没有很好地表现出来,所以下面是一张完整数据集的图表,显示了重叠的严重程度:

oug3syen

oug3syen1#

考虑到您的特定配色方案,最简单的方法可能是将箭头设置为全黑,但使用Alpha通道将灰色的箭头设置为灰色。这意味着即使在顶部绘制其他箭头,黑色箭头仍将是全黑的:

fviz_pca_var(pca,
             axes = c(1,2),
             select.var = list(contrib = 200),
             alpha.var = ifelse(markers_vec == 0, 0.2, 1),
             label = "none") + 
  theme_bw()

相关问题