如何1)使用ggplot2增加黄色圆圈of PCA-Bioplot内文本的大小?2)我们称之为什么?使用的代码:
p <- fviz_pca_biplot(zom, col.ind = df$Rm,
palette = "jco",
geom.ind = "point",
gradient.cols = c("white", "#2E9FDF", "#FC4E07" ),
pointsize = 3,
legend.title = "",
title = "PCA - Biplot")
p + theme(
panel.background = element_rect(fill = "lightblue",
colour = "lightblue",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white")
) +
theme(axis.text.x = element_text(size = 15)) +
theme(axis.text.y = element_text(size = 15)) +
theme(axis.title = element_text(size = 15, face = "bold"))
这里是dput(zom)
的输出
structure(list(sdev = c(1.3869502921823, 1.05877006549918,
1.0384037123946,
1.02795716229601, 0.816102138623649, 0.392904488803137), rotation = structure(c(-0.680441687434053,
0.590163481953139, -0.249790660774574, 0.256430440458904, -0.221341290032775,
-0.107527963308749, 0.0294273368056, -0.00209518665138356, -0.00651856640667369,
0.725574197057669, 0.662242320319373, 0.184565284047572, 0.0458337707228322,
0.466044566553159, 0.868088194460935, -0.060792787460819, 0.105497140660582,
-0.110901778120757, -0.0216966746984257, -0.021753686428234,
-0.16212211830016, -0.165694951555159, 0.424605461060344, -0.874658696668905,
0.213195863024978, -0.235202123804291, 0.172581273328464, 0.612922824182556,
-0.562795160546884, -0.42074981628564, 0.698648112863565, 0.615395705894065,
-0.357655062278663, 0.0309926666830973, -0.0654622449952845,
-0.00399312882564253), .Dim = c(6L, 6L), .Dimnames = list(c("Rm",
"IC", "Dose", "CT", "pH", "Na"), c("PC1", "PC2", "PC3", "PC4",
"PC5", "PC6"))), center = c(Rm = 83.7809291198966, IC = 253.125,
Dose = 9.4375, CT = 107.5, pH = 4.5625, Na = 0.0190625), scale = c(Rm = 28.5351607580893,
IC = 477.02821829807, Dose = 2.53735253655002, CT = 31.7141841087582,
pH = 1.89632608788123, Na = 0.0885803604822079), x = structure(c(2.86546265651538,
2.86546265651538, 2.86546265651538, 0.60097528700688, 0.61271514739821,
0.641028928342007, -0.00166899411927806, 0.0135237663871491,
0.00799912620299387, -0.502873485889389, -0.500801745820331,
-0.497348845705234, -0.994409857337228, -0.995100437360248, -0.99531410281937,
0.793079692895072, 0.814699819791746, 0.758741844294473, -0.497841091145642,
-0.495933432890053, -0.496569318975249, -0.732555087675326, -0.735098632016111,
-0.734462745930915, -0.967904970290207, -0.967269084205011, -0.969812628545796,
-1.2007113085643, -1.20261896681989, -1.2007113085643, -1.42970233032722,
-1.4335176468384, -1.42715878598644, -1.42310449838764, -1.41665970698363,
-1.41988210268563, -1.34353675243178, -1.34224779415098, -1.34353675243178,
-1.21967377951517, -1.21902930037477, -1.22031825865558, -0.984837416489995,
-0.984192937349593, -0.98290397906879, -0.740978345499194, -0.742911782920398,
-0.742911782920398, -0.500986149350802, -0.5003416702104, -0.5003416702104,
-0.510547262560963, -0.51312517912257, -0.511836220841767, -0.604331031137238,
-0.606908947698845, -0.60497551027764, -1.0228663914062, -1.02093295398499,
-1.04348972389905, -0.523599248811126, -0.530861907144586, -0.527230577977856,
-0.497501592642528, -0.502890457771311, -0.500869633348017, -0.462781288821409,
-0.467708092167455, -0.468200772502059, -0.423803526770102, -0.434544845776796,
-0.435977021644356, -0.319071745898057, -0.338233491768927, -0.338039938780333,
-0.228567562788233, -0.238737064518394, -0.243821815383475, 0.25922674074255,
0.221155289964151, 0.22301243390456, 1.21671761800511, 1.21432346858796,
1.52077459398376, 2.07813858975284, 2.08093738414191, 2.07394039816924,
2.39845560227458, 2.64196689212576, 2.67412876059667, 3.21201297175126,
2.94149420651544, 2.9555211054536, 3.66033884779045, 3.70419306056261,
3.61374374672004, -0.0114380621485446, -0.0114380621485446, -0.0114380621485446,
0.0728420386799, 0.0723343201903272, 0.0711098226566515, 0.0784251894042363,
0.077768141947142, 0.0780070682951763, 0.0659682324113423, 0.0658786350308294,
0.065729306063308, 0.0530931543093882, 0.0531230201028926, 0.0531322605794027,
-0.67843033279501, -0.679365347165407, -0.676945309971438, 0.0657505944009178,
0.0656680931329416, 0.0656955935556004, 0.764253319560671, 0.764363321251306,
0.764335820828648, 1.46278354514308, 1.46275604472043, 1.46286604641106,
2.16120376903486, 2.16128627030284, 2.16120376903486, 2.85945899039069,
2.85962399292664, 2.85934898870005, -2.56547983623093, -2.56575855673085,
-2.56561919648089, -2.33663870242347, -2.33669444652346, -2.33663870242347,
-1.99357210606224, -1.99359997811223, -1.99354423401224, -1.30688147233992,
-1.30690934438992, -1.3069650884899, -0.620581047317498, -0.620497431167523,
-0.620497431167523, 0.0658866100048786, 0.0658587379548867, 0.0658587379548867,
0.0866110365655697, 0.0867225247655376, 0.0866667806655536, 0.273465340211693,
0.273576828411661, 0.273493212261685, 1.10400323743889, 1.10391962128891,
1.10489514303863, 0.065636765647606, 0.0659508567693429, 0.0657938112084745,
0.0657359119718712, 0.0659689664011826, 0.0658815709901908, 0.0654621511663813,
0.0656752226229314, 0.0656965297685864, 0.0650042663432287, 0.0654688005097615,
0.0655307383986326, 0.0629304930929429, 0.0637591888650256, 0.0637508182006611,
0.0614720265162713, 0.0619118310698211, 0.062131733346596, 0.0428317934501707,
0.0444782848768771, 0.0443979682219158, 0.013700820438679, 0.0138043611866411,
0.000551145447487342, 0.00100264361519338, 0.000881603022505242,
0.00118420450422559, -0.000572213614854114, -0.0111034448353269,
-0.0124943621663328, -0.0234784360129627, -0.01177920158356,
-0.0123858285539735, -0.0183113221897244, -0.0202079030627412,
-0.016296205012144, -3.59319854690713, -3.59319854690713, -3.59319854690713,
-2.76968040684304, -2.77047119035826, -2.77237837413028, -1.7226096733703,
-1.72363304027236, -1.72326090685343, -0.0113869364898592, -0.0115264865219577,
-0.0117590699087883, 1.69918456690746, 1.69923108358482, 1.6992454758448,
-0.194221221837599, -0.195677528759236, -0.191908263785587, -0.0117259128211618,
-0.011854410490718, -0.0118115779341992, 0.0996245198176483,
0.0997958500437233, 0.0997530174872045, 0.211017785012977, 0.210974952456458,
0.211146282682533, 0.322239719982231, 0.322368217651787, 0.322239719982231,
0.433204659612372, 0.433461654951485, 0.433033329386297, 0.208408019332093,
0.207973905583592, 0.208190962457842, 0.189325883721603, 0.189239060971902,
0.189325883721603, 0.160398800681917, 0.160355389307067, 0.160442212056767,
0.103412862099547, 0.103369450724697, 0.103282627974997, 0.0458191642692768,
0.045949398393827, 0.045949398393827, -0.0115140653118934, -0.0115574766867435,
-0.0115574766867435, -0.0242076167494765, -0.0240339712500762,
-0.0241207939997764, -0.137928643189524, -0.137754997690123,
-0.137885231814674, -0.643239663701245, -0.643369897825795, -0.641850499706042,
-0.0364985972647002, -0.0360093929389785, -0.0362539951018394,
-0.0117487810504896, -0.0113857932833816, -0.0115219136960471,
0.0124202235191262, 0.0127520873351289, 0.0127852737167291, 0.036302450591143,
0.0370259735053109, 0.0371224432272, 0.08226328682603, 0.0835540000246974,
0.0835409625176402, 0.129182477708807, 0.129867483667838, 0.130209986647354,
0.149340662283331, 0.151905111490791, 0.1517800164075, 0.349922419926923,
0.350083687082491, 0.329441491169845, 0.822052579751251, 0.821864056175024,
0.822335365115591, 1.06555363726496, 1.04915099640157, 1.04698460987244,
1.27583059071595, 1.29405242410891, 1.29310758830335, 1.77578636183525,
1.77283239242016, 1.77892495433878, 0.672936886655186, 0.672936886655186,
0.672936886655186, 0.479220758179566, 0.479595097284032, 0.480497915124216,
0.277739272329123, 0.278223711170197, 0.278047551591625, -0.0420180024733124,
-0.0419519426313478, -0.0418418428947401, -0.361466998013246,
-0.361489017960568, -0.361495830932269, -0.455957641564343, -0.455268258669557,
-0.457052543809002, -0.0418575387131908, -0.0417967108107098,
-0.0418169867782035, 0.405920946144967, 0.405839842274993, 0.405860118242486,
0.853679155035632, 0.853699431003125, 0.853618327133151, 1.30151846779627,
1.30145763989379, 1.30151846779627, 1.74947943636187, 1.74935778055691,
1.74956054023185, 0.559121494788181, 0.559326994458725, 0.559224244623453,
0.506834071572686, 0.506875171506794, 0.506834071572686, 0.428546786518823,
0.428567336485878, 0.428526236551769, 0.271561217070011, 0.271581767037066,
0.271622866971174, 0.114863347159961, 0.114801697258797, 0.114801697258797,
-0.0419578225524164, -0.041937272585362, -0.041937272585362,
-0.140617453481398, -0.140699653349615, -0.140658553415506, -1.02880073144688,
-1.0288829313151, -1.02882128141394, -4.97633676676118, -4.97627511686002,
-4.97699436570692, -0.0405525920849589, -0.0407841703938968,
-0.0406683812394278, -0.041846713408512, -0.0420185436415093,
-0.0419541073041353, -0.0428658915817397, -0.0430229884373209,
-0.043038698122879, -0.0437493157469923, -0.0440918151978991,
-0.0441374817913533, -0.0446623719840725, -0.0452733665402437,
-0.0452671948780602, -0.0460290917254437, -0.0463533581173464,
-0.0465154913132977, -0.0347277538465103, -0.0359417063395607,
-0.0358824891447778, -0.0254597979394965, -0.0255361381785541,
-0.0157645875791891, -0.0405178971936921, -0.0404286543790193,
-0.0406517614157015, -0.0515669711290927, -0.0438023303981306,
-0.0427768118110223, -0.0468885025423077, -0.0555143080411957,
-0.0550670440523645, -0.0751186194383116, -0.0737202768525403,
-0.0766043584356935, -0.668641240557885, -0.668641240557885,
-0.668641240557885, 0.115210292634065, 0.111531961758482, 0.102660693176194,
0.415544844033262, 0.410784651135449, 0.412515630371017, 0.758439070992234,
0.757789953778896, 0.756708091756666, 1.09830408428896, 1.09852045669341,
1.09858740231534, 1.01909703201597, 1.0123230178755, 1.02985576035672,
0.756862322006555, 0.756264614876513, 0.756463850586527, 0.16369709766401,
0.164494040504066, 0.164294804794052, -0.429268890968521, -0.429468126678535,
-0.42867118383848, -1.02303182244111, -1.02243411531107, -1.02303182244111,
-1.61799016817378, -1.61679475391369, -1.61878711101383, -1.46711799255508,
-1.46913727339982, -1.46812763297745, -1.27344956363829, -1.27385341980724,
-1.27344956363829, -0.984360416854425, -0.984562344938899, -0.984158488769951,
-0.402143561597215, -0.402345489681689, -0.402749345850636, 0.177246300477365,
0.177852084730785, 0.177852084730785, 0.757847731058786, 0.757645802974312,
0.757645802974312, 0.709540797223577, 0.710348509561471, 0.709944653392524,
0.277201529720376, 0.278009242058271, 0.27740345780485, -1.64376785095747,
-1.64437363521089, -1.63730615225432, 0.76756856738881, 0.769844102147852,
0.768706334768331, 0.756755950398666, 0.758444388619123, 0.757811224286452,
0.743241687048829, 0.744785352157408, 0.744939718668266, 0.728393477677695,
0.731758945752254, 0.732207674828863, 0.690307527141652, 0.696311281796089,
0.696250637809681, 0.656679364891814, 0.659865671283581, 0.661458824479464,
0.498572335960762, 0.510500875841853, 0.509918995847653, 0.172214430172341,
0.172964564622694, 0.0769473549774294, -0.15039991278267, -0.151276830520407,
-0.149084536176064, -0.277118621709646, -0.353415533781453, -0.363492484432446,
-0.558379307593243, -0.473620418354126, -0.47801532372208, -0.751562771947797,
-0.765303165741861, -0.736963603541604, -0.950551140925346, -0.950551140925346,
-0.950551140925346, 0.890455667090167, 0.878401685890669, 0.849330319468351,
0.783118353632983, 0.767519083845397, 0.773191545586337, 0.0875561076337164,
0.0854289344808635, 0.0818836458927761, -0.617932946412196, -0.617223888694578,
-0.617004506236747, -0.93434308694539, -0.956541698722385, -0.899086468240751,
0.0823890622338935, 0.0804303611947473, 0.0810832615411293, 0.0146537360723359,
0.0172653374578647, 0.0166124371114824, -0.0524286897428399,
-0.0530815900892218, -0.0504699887036933, -0.122122716943544,
-0.120164015904398, -0.122122716943544, -0.195734146222542, -0.191816744144249,
-0.19834574760807, -0.034706086263485, -0.0413233195038457, -0.0380147028836654,
-0.0236101458388703, -0.0249335924869422, -0.0236101458388703,
-0.0115982984702002, -0.0122600217942363, -0.0109365751461641,
0.0256598627478605, 0.0249981394238244, 0.0236746927757521, 0.0536538974294171,
0.0556390674015252, 0.0556390674015252, 0.0856182720551895, 0.0849565487311537,
0.0849565487311537, 0.082520587093274, 0.0851674803894179, 0.0838440337413459,
0.0625821023244647, 0.0652289956206089, 0.0632438256485009, -0.024268790006146,
-0.026253959978254, -0.00309364363699328, 0.0448281541005945,
0.0522851377521673, 0.048556645926381, 0.082040479845571, 0.0875735336284713,
0.0854986384598838, 0.110399443691105, 0.115458072407909, 0.115963935279589,
0.134387033452647, 0.145415755519914, 0.14688625179555, 0.154869509916844,
0.174543962318986, 0.17434523047654, 0.189960268781612, 0.200401873585886,
0.205622675988024, -0.182869295310527, -0.143779175273041, -0.145686010396821,
-0.52589683056877, -0.523438621433295, -0.838089390774116, -0.130201229032513,
-0.133074910134547, -0.125890707379461, 0.180993818464076, -0.0690330482863351,
-0.102055464649597, -0.0142490124624156, 0.263507962626653, 0.249105749103516,
0.805594777492901, 0.760567167397577, 0.853436613219184), .Dim = c(96L,
6L), .Dimnames = list(NULL, c("PC1", "PC2", "PC3", "PC4", "PC5",
"PC6")))), class = "prcomp")
非常感谢最好的祝福苏拉杰
您可以在ggplot对象的'aes_params'部分中直接编辑该对象的两个文本层的字体大小。使用此功能时,似乎两个文本层分别是第2层和第5层,但是您的文本层可能有所不同,因此请寻找一个显示GeomText的层。
这里是一些示例代码:
library(factoextra)
data("decathlon2")
df <- decathlon2[1:23, 1:10]
library("FactoMineR")
test <- PCA(df, graph = FALSE)
p <- fviz_pca_biplot(res.pca)
p
然后使用:
p$layers[[5]]$aes_params$size <- 10
p
您可以使用labelsize = 6
来更改标签的大小
p <- fviz_pca_biplot(zom,
palette = "jco",
geom.ind = "point",
gradient.cols = c("white", "#2E9FDF", "#FC4E07" ),
pointsize = 3, labelsize = 6,
legend.title = "",
title = "PCA - Biplot")
p + theme(
panel.background = element_rect(fill = "lightblue",
colour = "lightblue",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white")
) +
theme(axis.text.x = element_text(size = 15)) +
theme(axis.text.y = element_text(size = 15)) +
theme(axis.title = element_text(size = 15, face = "bold"))
注意您的数据集中Rm
中没有,所以我删除了col.ind = df$Rm
部分。