Related
I want to add labels to the x and y axis where geom_segment lines end at. Something like this:
The code I'm working with:
ggplot(exp, aes(voltage)) +
geom_line(aes(y = current , colour = "current")) +
geom_segment(x = 0,
xend = 4.44993305,
y = 0.039496649, yend = max(
0.039496649)) +
geom_segment(x = 4.44993305,
xend = 4.44993305,
y = 0, yend = max(
0.039496649))+
geom_text(x = 4.44993305 + 0.1,
y = 0.039496649+0.0020, label = "MPP", check_overlap = TRUE) +
scale_colour_manual(values = c("red", "forestgreen")) +
annotate(geom = "point", x = 4.44993305, y = 0.039496649, colour = "orange", size = 3) +
labs(colour = "", x = "Voltage(V)", y = "Current(mA)", title = "P-V Curve") +
scale_y_continuous(expand = c(-0.05, 0), limits = c(0, 0.05)) +
scale_x_continuous(expand = c(0, 0), limits = c(0, 6))
reproducible code:
structure(list(current = c(0.04465198144317, 0.04463520273566,
0.04460114613175, 0.04457135125995, 0.0445214137435, 0.04453720897436,
0.04449214786291, 0.04451920464635, 0.04460586234927, 0.04455019906163,
0.04449771717191, 0.04447644948959, 0.04445287585258, 0.04446478188038,
0.04446309804916, 0.04443653672934, 0.04444691166282, 0.0444468036294,
0.04446209222078, 0.04440823569894, 0.04440270736814, 0.04439539834857,
0.04439954087138, 0.04436922073364, 0.04438590630889, 0.0443644374609,
0.04435379058123, 0.04435301944613, 0.04435969889164, 0.04429738968611,
0.04429103061557, 0.04427329823375, 0.04427855834365, 0.04435616359115,
0.04431574419141, 0.04425121843815, 0.04425748437643, 0.04426665976644,
0.04420702531934, 0.04421706870198, 0.04422586038709, 0.04420934617519,
0.04419368878007, 0.04420448094606, 0.04418215155602, 0.0441633015871,
0.04416632652283, 0.04419567808509, 0.0441645719111, 0.04414548352361,
0.0441205650568, 0.04409914091229, 0.04407843202353, 0.04408247023821,
0.0440976023674, 0.04407130554318, 0.04406511038542, 0.04406157508492,
0.04411358013749, 0.04408717527986, 0.04403834789991, 0.04397377744317,
0.04399513080716, 0.04394119232893, 0.04393403977156, 0.04395672306418,
0.04391529783607, 0.04388456046581, 0.04384018108249, 0.04377613589168,
0.04371620714664, 0.04360201209784, 0.04351374134421, 0.04337716847658,
0.04323555156589, 0.0430811829865, 0.04289939254522, 0.04273791983724,
0.04255214333534, 0.04230800643563, 0.04205309599638, 0.04180316627026,
0.04153088480234, 0.04128103330731, 0.04098862782121, 0.0406355522573,
0.04026722535491, 0.03988171741366, 0.03949664905667, 0.03904519975185,
0.03858072310686, 0.03809594735503, 0.03754813969135, 0.03698132932186,
0.03636532649398, 0.03573113679886, 0.03502003848553, 0.03427068144083,
0.03349439799786, 0.03265217319131, 0.03173480927944, 0.03077974915504,
0.0297338180244, 0.02861846797168, 0.02742668054998, 0.02613251283765,
0.02471670508385, 0.02320869639516, 0.02159749343991, 0.01984822377563,
0.01790586858988, 0.01580262370408, 0.01354998257011, 0.0110809514299,
0.008333564735949, 0.005422144662589, 0.002235329709947), voltage = c(0.0497902818024,
0.1001076325774, 0.1500261873007, 0.200014218688, 0.2499825656414,
0.2999092638493, 0.3499111533165, 0.3998158872128, 0.4498016238213,
0.5000447034836, 0.5500398874283, 0.6000450849533, 0.6499763131142,
0.6999563574791, 0.749892115593, 0.7998710870743, 0.8501480221748,
0.9000863432884, 0.9500870704651, 1.000000834465, 1.0499948263168,
1.0999064445496, 1.1499096155167, 1.1998677253723, 1.2501357793808,
1.3001333475113, 1.3500553369522, 1.4000434875488, 1.4499852657318,
1.4999231100082, 1.549925327301, 1.6001867055893, 1.6501588821411,
1.7000889778137, 1.7500828504562, 1.800025343895, 1.8499475717545,
1.899978518486, 1.949893116951, 2.0002207756042, 2.0501630306244,
2.1001031398773, 2.1501016616821, 2.2000172138214, 2.2499938011169,
2.299911737442, 2.3502452373505, 2.4001979827881, 2.4501132965088,
2.5001027584076, 2.5500218868256, 2.5999536514282, 2.6498956680298,
2.6998517513275, 2.7501895427704, 2.8001124858856, 2.8500940799713,
2.9000113010406, 2.9500093460083, 2.9999513626099, 3.0498661994934,
3.1002125740051, 3.1501111984253, 3.2001020908356, 3.2500350475311,
3.3000183105469, 3.3500154018402, 3.399943113327, 3.4499311447144,
3.5001940727234, 3.550187587738, 3.6001205444336, 3.6500551700592,
3.7000305652618, 3.7499585151672, 3.7999482154846, 3.8501899242401,
3.9001405239105, 3.9500863552094, 4.0000004768372, 4.0499835014343,
4.0999245643616, 4.1499009132385, 4.1998748779297, 4.2501282691956,
4.300087928772, 4.3500247001648, 4.3999924659729, 4.449933052063,
4.4998655319214, 4.5498738288879, 4.6001214981079, 4.6501264572144,
4.7000713348389, 4.7500491142273, 4.8000221252441, 4.8499178886414,
4.8999338150024, 4.9498329162598, 5.0001378059387, 5.0500822067261,
5.1000084877014, 5.1500005722046, 5.1999025344849, 5.2499060630798,
5.2998147010803, 5.3501005172729, 5.4000744819641, 5.4499711990356,
5.4999628067017, 5.5498695373535, 5.5998673439026, 5.6497716903687,
5.6997165679932, 5.7502884864807, 5.8000655174255, 5.8499555587769
), PP = c(0.00222323473909097, 0.00446832447547921, 0.00669133990338782,
0.0089149039981273, 0.0111295772335824, 0.0133571215574027, 0.0155682987722391,
0.0177994853036886, 0.020063789316651, 0.0222770910799081, 0.0244755193440537,
0.0266878749124022, 0.0288933163539832, 0.0311234067610935, 0.0333425266619036,
0.0355435009395142, 0.0377864540419245, 0.0400059609496442, 0.04224285894479,
0.0444082727560584, 0.0466226130110058, 0.0488307847519388, 0.0510554589725266,
0.0532371959582141, 0.0554884095769874, 0.0576796845864956, 0.0598800716882498,
0.0620961560286796, 0.0643209097851773, 0.0664426785032353, 0.068647790123336,
0.070845543246237, 0.073066656339177, 0.0754094248194155, 0.0775562239145906,
0.0796533146869037, 0.0818740257541394, 0.0841057026413645, 0.0861989743910597,
0.0884438994540186, 0.090670223963168, 0.092844186714439, 0.0950209236818901,
0.0972506190093721, 0.0994095671210524, 0.101571695684362, 0.103801698561548,
0.106078377387785, 0.108208204874005, 0.110368245128615, 0.112508406553953,
0.114655722439755, 0.116803246072698, 0.119016134475474, 0.121276764892071,
0.123404612920738, 0.125589710242767, 0.127779065687917, 0.130135473691482,
0.132259381554438, 0.134311068741467, 0.136328057755817, 0.138589554231821,
0.140616301445618, 0.142787169037195, 0.145057990983433, 0.147116924127234,
0.149205009137113, 0.151245606106401, 0.153224971374792, 0.155200735994985,
0.156972499532076, 0.158827556562052, 0.160496849197857, 0.16213152475246,
0.163706264410516, 0.165170808933627, 0.166683893064858, 0.168084640773841,
0.169232045916551, 0.170314344969572, 0.171389828259531, 0.172349056768834,
0.17337517472235, 0.174206925818462, 0.1747364477406, 0.175163424900961,
0.175479256150164, 0.175757444083009, 0.175698148550336, 0.175537422363473,
0.17524598641866, 0.174603597797929, 0.173814885869911, 0.172737086901316,
0.171510247194652, 0.169844311111882, 0.167924070855098, 0.165791673720114,
0.163265365619927, 0.160263395675946, 0.156976981940024, 0.153129179839487,
0.148813244139014, 0.143987496509493, 0.138497475713147, 0.132236856654388,
0.125328689163156, 0.11770571721887, 0.109164492545057, 0.0993752346268299,
0.0884925964284587, 0.0765543079295968, 0.063158282454129, 0.0479204013524691,
0.0314487942879752, 0.0130765794624036)), row.names = c(NA, -117L
), class = c("tbl_df", "tbl", "data.frame"))
I made a package specifically for this. lemon
library(lemon)
ggplot(exp, aes(voltage)) +
... +
annotate_x_axis('IM', x = 4.44993305, side = 'bottom', print_value = FALSE) +
annotate_y_axis('M', y = 0.039496649, side='left', print_value = FALSE)
(where the ... is placeholder for the rest of your ggplot-commands)
How
1) to increase the size of the text inside the yellow circle of PCA-Bioplot using ggplot2?
2) what we called it?
USED Code:
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"))
here is the output of 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")
many thanks
best regards
Suraj
You can change the size of the label by using labelsize = 6 like
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"))
Note in your dataset Rm was not there so I have removed col.ind = df$Rm part.
You can directly edit the font size of both the text layers of this object in the 'aes_params' section of the ggplot object. It seems that the two text layers are layers 2 and 5 when using this function but yours may be different so look for the one that says GeomText.
Here is some example code:
library(factoextra)
data("decathlon2")
df <- decathlon2[1:23, 1:10]
library("FactoMineR")
test <- PCA(df, graph = FALSE)
p <- fviz_pca_biplot(res.pca)
p
Then use:
p$layers[[5]]$aes_params$size <- 10
p
Hope that is what you are looking for! Again you may need to change the layer number to something other than 5 here.
In the following script:
dataset_prices2017 <- read.csv("/home/nasser/Desktop/prices2017.csv")
dataset_prices2018 <- read.csv("/home/nasser/Desktop/prices2018.csv")
dataset_prices2019 <- read.csv("/home/nasser/Desktop/prices2019.csv")
selectedDF <- dataset_prices2017 %>% select(Price, Volume)
plot_17 <- ggplot(selectedDF, aes(Price, Volume)) + geom_hex(bins = 30) + theme_bw() +
geom_smooth(method="lm") + labs(fill = "Count")
plot_17 <- plot_17 + scale_fill_gradientn(colors = brewer.pal(3,"Dark2"), labels = percent(0.25*0:4))
selectedDF <- dataset_prices2018 %>% select(Price, Volume)
plot_18 <- ggplot(selectedDF, aes(Price, Volume)) + geom_hex(bins = 30) + theme_bw() +
geom_smooth(method="lm") + labs(fill = "Count")
plot_18 <- plot_18 + scale_fill_gradientn(colors = brewer.pal(3,"Dark2"), labels = percent(0.25*0:4))
selectedDF <- dataset_prices2019 %>% select(Price, Volume)
plot_19 <- ggplot(selectedDF, aes(Price, Volume)) + geom_hex(bins = 30) + theme_bw() +
geom_smooth(method="lm") + labs(fill = "Count")
plot_19 <- plot_19 + scale_fill_gradientn(colors = brewer.pal(3,"Dark2"), labels = percent(0.25*0:4))
fullPlot <- grid.arrange(plot_17, plot_18, plot_19, ncol=3, nrow = 1)
Running this script generates the following error:
Error in f(..., self = self) : Breaks and labels are different lengths
Note that I got this error after adding the last line in the script.
Do you have any idea how to solve this error?
Just figured out that the problem is caused by the data of plot_18. The data for that plot:
structure(list(Price = c(0.5219551282, 0, 0, 0.194543297766667,
0.46875, 0.8108108108, 0.2962962963, 0.436213991763333, 0, 0.1904761905,
0.0208333333, 0, 0, 0.630769230766667, 0.0074626866, 0, 0.7037037037,
0.70736842106, 0.597250859103333, 0.88, 0.6666666667, 0, 0.13523391815,
0.035490830643333, 0.02705627708, 0.0666666667, 0.29674796745,
0.41944444446, 0.1621621622, 0.09127725854, 0.9234567901, 0.582170542623333,
0.28962962964, 0.79312169317, 0.793380614656667, 0.875187969906667,
0.03595113442, 0.113242009126667, 0.0293040293, 0.381194511696667,
0.0344827586, 0.09544715448, 0.161734693876667, 0.123095238113333,
0.7075949367, 0, 0.8125, 0.8571428571, 0.9, 0.9333333333, 0.79920634921,
0.0085106383, 0.713333333323333, 0.62150537635, 0.232905982933333,
0.868, 0.851580459763333, 0.743589743583333, 0.744298245626667,
0, 0.434379671133333, 0.797916666666667, 0.2222222222, 0.612962962953333,
0.591333333333333, 0.516666666666667, 0.53809523808, 0.611515151526667,
0.64246575339, 0.7101449275, 0.122445561153333, 0.65848765432,
0.2558526441, 0.641025641, 0.347892720293333, 0.0769230769, 0.353939393936667,
0.978333333333333, 0.755238095256667, 0.863333333333333, 0.6751243781,
0.67297297298, 0.5344017094, 0.0057142857, 0.921568627463333,
0.52644927536, 0.128333333333333, 0, 0.1904761905, 0.471929824536667,
0.15972222225, 0, 0, 0, 0.446258503403333, 0.44210526318, 0.82189054726,
0.628169014093333, 0, 0.2307692308, 0.191304347823333, 0.4004385965,
0.83441734419, 0.20449172577, 0.746598639443333, 0.211494252846667,
0.8695652174, 0.519999999993333, 0.113333333333333, 0.637142857133333,
0.699420289853333, 0.7391304348, 0.457575757543333, 0.461904761866667,
0.788888888883333, 0.503065134103333, 0.499616858236667, 0.793888888883333,
0.70901542112, 0.591358024693333, 0.47769028871, 0.456692913383333,
0.40625, 0, 0.7678571429, 0.796969696963333, 0.914886731406667,
0.102424242446667, 0.487804878, 0.1923076923, 0, 0.3658536585,
0.634782608673333, 0.385028248613333, 0.69864864864, 0.60404040406,
0.814880952386667, 0.533582089543333, 0.8695652174, 0, 0.715942029016667,
0.74987277353, 0.864455782326667, 0.624999999986667, 0.3333333333,
0.4642857143, 0.10434782606, 0.078095238096667, 0.0119047619,
0.427472527466667, 0.0909090909, 0.6071428571, 0.6071428571,
0.064516129, 0.500266666666667, 0.5263157895, 0, 0.75256410254,
0.691836734676667, 0.2083333333, 0.5, 0.85625, 0.6666666667,
0.60065359476, 0.5, 0.279012345676667, 0.1176470588, 0.5185185185,
0.8085106383, 0.5365853659, 0.9090909091, 0.82589928058, 0, 0,
0.03175438598, 0.511764705856667, 0.0196078431, 0.693650793643333,
0.18378378382, 0.10596205961, 0.022916666666667, 0.288888888903333,
0.306666666673333, 0, 0.68078703703, 0.744217687073333, 0.6428571429,
0.828462709286667, 0.887265917566667, 0.713710691823333, 0.76077643908,
0.72816091955, 0.648370927326667, 0.76565656568, 0.315458937203333,
0.29583333335, 0.714765100693333, 0.812159329126667, 0.05, 0.713681592026667,
0.10976645433, 0.75625, 0, 0.42777777777, 0.6842105263, 0.79678362574,
0.71025641027, 0.88205128204, 0.84959349595, 0.650104821806667,
0.9032258065, 0.895652173936667, 0.374390243886667, 0.531182795713333,
0.8429378531, 0.08, 0.030075188, 0, 0.0134228188, 0.93787878788,
0.7804878049, 0.556666666676667, 0.506630824373333, 0, 0.368527918786667,
0.7439716312, 0.21818181816, 0.7647058824, 0.90188034188, 0.792857142846667,
0.157142857183333, 0.19814814816, 0.799047619056667, 0.8947368421,
0, 0.318562091513333, 0.40884353743, 0.085815602833333, 0.14280701756,
0.804624277473333, 0.5714285714, 0.867759562826667, 0.624074074063333,
0.24139784949, 0.42, 0.716269841283333, 0.692539109493333, 0.398290598286667,
0.474193548386667, 0.5384615385, 0.225925925923333, 0.1666666667,
0.156540084396667, 0.6666666667, 0.82459546925, 0.683681592026667,
0.70945945945, 0.677494692146667, 0.65738396624, 0.83459119496,
0.794179894193333, 0.533630952366667, 0.639999999996667, 0.620648967546667,
0.301428571416667, 0.10307017545, 0.72935323382, 0.43850129199,
0.43074712644, 0.432835820883333, 0.1666666667, 0.668965517236667,
0.062745098026667, 0.625, 0.0425531915, 0.617567567546667, 0.069005847956667,
0.081836327346667, 0.6956521739, 0.9818181818, 0.5, 0.5, 0.4324324324,
0.2666666667, 0.2857142857, 0, 0.4027777778, 0.71195402298, 0.64342105263,
0.7741935484, 0.186419753086667, 0.822710622716667, 0, 0, 0.021875,
0.091484184913333, 0, 0, 0, 0, 0.6666666667, 0.737435897473333,
0.759420289843333, 0.6666666667, 0.295928753186667, 0.75420054203,
0.039602925803333, 0.6666666667, 0.183333333326667, 0.74521072797,
0.43983739835, 0.653645833333333, 0, 0.1935483871, 0.22883895131,
0.72955465589, 0.380459770086667, 0.844061302676667, 0.952873563223333,
0.3325), Volume = c(0.002414102564097, 0.001174398625467,
0.0010256410256, 0.001051838671393, 0.002878125, 0.004077477477493,
0.00177037037037, 0.003053909465023, 0.00206551724138, 0.002257142857167,
0.002033333333333, 0.001, 0.001072380952367, 0.0029717948718,
0.002232587064677, 0.00201036414567, 0.0021, 0.00292771929824,
0.003005841924393, 0.008772666666667, 0.002482539682533, 0.0016028328612,
0.001884795321637, 0.001899568500543, 0.001675757575777, 0.0012,
0.002775880758787, 0.002668333333327, 0.00151171171169, 0.001388785046723,
0.00607530864197, 0.00415348837209, 0.002834814814827, 0.008986243386227,
0.0020964539007, 0.005417543859647, 0.00207905759162, 0.002877168949767,
0.001929792429827, 0.003026553672313, 0.00150344827588, 0.001880108401087,
0.001844047619057, 0.002190952380963, 0.00348396624472, 0.0010344827586,
0.006220833333333, 0.00308730158726, 0.002998333333333, 0.00227777777778,
0.002014484126987, 0.00126765957446, 0.003718888888883, 0.005132616487453,
0.002628205128203, 0.004248, 0.007026293103447, 0.002628205128207,
0.003443421052633, 0.001, 0.002645739910313, 0.008983333333333,
0.0017777777778, 0.002870370370367, 0.003363333333333, 0.00210256410256,
0.003542857142857, 0.002534848484847, 0.00231506849313, 0.002258454106293,
0.001163484087093, 0.005761111111113, 0.00211039809863, 0.002683760683757,
0.016383908045983, 0.002228205128207, 0.00215212121213, 0.004805,
0.010981904761907, 0.00828875, 0.00274427860695, 0.002558108108107,
0.002019444444443, 0.0015914285714, 0.004362745098053, 0.002043840579703,
0.002366666666667, 0.001103703703693, 0.001742857142873, 0.004219298245603,
0.00166712962963, 0.001, 0.0013430107527, 0.0015434782609, 0.002538775510207,
0.003559899749367, 0.0025592039801, 0.00343615023474, 0.001239955849933,
0.002176923076903, 0.001110144927567, 0.00341403508773, 0.003459349593493,
0.002460283687937, 0.00319863945578, 0.00226666666666, 0.018426086956527,
0.003018888888873, 0.002331666666667, 0.003414285714283, 0.002526956521737,
0.00519710144927, 0.002732034632027, 0.002861904761897, 0.003106666666673,
0.002896934865907, 0.00257969348659, 0.003066111111117, 0.00349881376038,
0.00244814814815, 0.00230262467191, 0.002416272965877, 0.00248125,
0.001801666666667, 0.007639880952377, 0.002253030303033, 0.009329126213587,
0.00166909090911, 0.00293821138211, 0.004464102564097, 0.002315942029033,
0.003039024390237, 0.015501449275363, 0.008321468926553, 0.009915315315317,
0.004964646464643, 0.00526488095237, 0.004199004975113, 0.00949130434782,
0.001162745098033, 0.00265942028985, 0.002461323155213, 0.013436054421777,
0.003893253968247, 0.001716666666667, 0.00195595238097, 0.0019130434783,
0.001076190476233, 0.001866269841277, 0.003128937728933, 0.0021,
0.00230238095237, 0.00248333333332, 0.00281397849465, 0.002320533333333,
0.002299122807017, 0.002, 0.00275, 0.002816326530617, 0.002254166666667,
0.00369761904762, 0.00381875, 0.003125925925927, 0.005600000000007,
0.00369861111111, 0.002507407407373, 0.0014117647059, 0.003214814814817,
0.002590070921973, 0.00297479674797, 0.01804242424242, 0.00463980815348,
0.001, 0.0010222222222, 0.001853947368427, 0.0017058823529, 0.0011568627451,
0.003668253968263, 0.00215675675675, 0.001922222222237, 0.002383333333333,
0.00296495726495, 0.04700512820514, 0.001080952380933, 0.007685648148143,
0.0026112244898, 0.014720238095237, 0.00248949771689, 0.00493520599251,
0.00640553459119, 0.004878313253013, 0.00365545977011, 0.004275689223057,
0.01131245791246, 0.003004106280193, 0.00678472222223, 0.005784004474273,
0.004531446540867, 0.001835, 0.00332611940299, 0.001566454352443,
0.01443125, 0.001049275362333, 0.007142424242427, 0.0240552631579,
0.007115204678353, 0.003953846153853, 0.00365705128204, 0.005986720867213,
0.002818448637317, 0.00557311827956, 0.00247934782609, 0.002582926829263,
0.003732258064523, 0.00645706214689, 0.004855999999993, 0.001249122807027,
0.0010241545894, 0.00103154362418, 0.013604545454543, 0.005505691056917,
0.002934444444437, 0.002545340501793, 0.0010238095238, 0.00221370558375,
0.00335000000001, 0.001788552188527, 0.00236274509804, 0.013679487179487,
0.005909523809527, 0.003596190476187, 0.002676851851847, 0.00611942857143,
0.005988596491227, 0.002, 0.002481045751637, 0.00392789115644,
0.00167568389058, 0.002203684210527, 0.003684778420043, 0.0097238095238,
0.00281311475409, 0.003364074074077, 0.002609677419357, 0.002558,
0.002856746031737, 0.00735330926595, 0.001780128205137, 0.00261075268818,
0.002848717948717, 0.00189058641975, 0.001945555555547, 0.001983966244727,
0.005273333333327, 0.004203883495147, 0.003079104477617, 0.003092342342337,
0.003043312101907, 0.00304556962024, 0.003135220125783, 0.004403703703707,
0.002158333333327, 0.004803902439023, 0.00234247787612, 0.0019919047619,
0.001954385964913, 0.003713432835827, 0.002959173126613, 0.00378965517242,
0.00259552238807, 0.002186111111113, 0.001156704980857, 0.002354901960793,
0.01525625, 0.0015957446809, 0.00489594594594, 0.001830409356733,
0.00169753825682, 0.00253671497585, 0.01430363636364, 0.0025,
0.016829166666667, 0.002627027027023, 0.002300000000033, 0.0022857142857,
0.002, 0.001732870370397, 0.002788850574713, 0.00302105263158,
0.008280645161293, 0.002154938271587, 0.003345421245423, 0.001345662100463,
0.001486666666667, 0.00210078125, 0.002824574209243, 0.001466666666667,
0.002, 0.002, 0.001147619047633, 0.00367654320988, 0.00385538461539,
0.003284541062797, 0.00693765432099, 0.001989058524173, 0.004204607046073,
0.002009299895507, 0.004667777777773, 0.00320292397661, 0.003397318007663,
0.00231788617884, 0.005576388888893, 0.001764102564133, 0.002895698924767,
0.001935205992517, 0.002502699055333, 0.002919540229867, 0.00350996168583,
0.003030459770113, 0.002411666666667)), .Names = c("Price",
"Volume"), class = "data.frame", row.names = c(NA, -320L
))
When I remove the labels = percent(0.25*0:4), the error is gone. However, I added this in order to show the legend labels as 25%, 50%, 75%, 100%. What should I do to solve this issue? It's important for me to show the legend labels as I mentioned.
I am guessing what your labels indicate are the quantiles of counts. So first let's get back what your original plot is without percentage labels:
library(scales)
library(ggplot2)
library(hexbin)
library(RColorBrewer)
plot_17 <- ggplot(selectedDF, aes(Price, Volume)) +
geom_hex(bins = 30) + theme_bw() +
geom_smooth(method="lm") + labs(fill = "Count")
plot_17_count <- plot_17 +
scale_fill_gradientn(colors = brewer.pal(3,"Dark2"))
The problem with defining a 0,0.25.. labels for every plot is, you might have different number of breaks depending on the range. You can see for the plot above (plot_17_count), it has only 3 breaks. For you to place the percentiles correctly, you need to access the hexbin count inside geom_hex.. which might not be so easy. One workaround is to transform the scale.
We define the quantiles you need, and a transformation
BR = percent(0.25*0:4)
# unfortunately no inverse, I just put in identity so the function works
min_max_trans = trans_new("min_max",function(i)i/(max(i)-min(i)),inverse=identity)
plot_17_perc <- plot_17 +
scale_fill_gradientn(colors = brewer.pal(3,"Dark2"),
trans=min_max_trans,labels=percent(0.25*0:4))
Put them together:
library(gridExtra)
grid.arrange(plot_17_count,plot_17_perc)
I have a dataset (randomized data, for this example) that I'm working with, and I need to only display a certain part of the matrix. Is there a way to keep the same parameters specified in the code, but to only display the part of the matrix that I need?
The code that I will show below generates the matrix shown here:
I like the size of everything, particularly speaking of the Pearson's correlation value legend on the right. However, I need to only display everything that is in the red box in the following picture:
Here is the code that I'm working with:
Data:
sen <- structure(list(STAGE3 = c(0.876917687075825, 0.412349699244156,
0.0276263864194565, 0.715878164202211, 0.113324379019157, 0.697977125373629,
0.495239700082692, 0.433931430983351, 0.969730865766935, 0.325140127448327,
0.571408271249494, 0.795998354603895, 0.677190885671071, 0.725950370073618,
0.773033245228681, 0.124492827494149, 0.392125485039593, 0.293970448598711,
0.574176683397314, 0.439175490268417, 0.187274945963726, 0.114361533064052,
0.984810340190489, 0.094824786617737, 0.365076362766766, 0.484529293489265,
0.0248352738577235, 0.370080530701056, 0.916058724203794, 0.698768788065752,
0.0486805863644058, 0.417384720565167, 0.575510045429799, 0.306442633779882,
0.352619466947156, 0.0468312121293604, 0.719674300918072, 0.245979619378491,
0.497903453826379, 0.815929672015352, 0.579266045428163, 0.493374660814721,
0.981395698013249, 0.501428573306618, 0.232710091203988, 0.295487027432436,
0.0358089940602796, 0.122221799715662, 0.475075779687791, 0.64716894430911,
0.411728227914661, 0.189801935164384, 0.995784139092795, 0.338669053292779,
0.888464605534105, 0.727167494736264, 0.359872858562472, 0.501785825883555,
0.131682859300131, 0.316615799479412), STAGE2 = c(0.731671739637962,
0.0349659624268288, 0.250468754401736, 0.692725665227725, 0.63127309683438,
0.267791520174364, 0.683510378409481, 0.0930250575768417, 0.0469303813447592,
0.664296422188774, 0.104791391299402, 0.769846767284999, 0.6757286415883,
0.752123872001356, 0.90542496106528, 0.495894318363979, 0.693023609703169,
0.268140720274296, 0.715499146536921, 0.28736047756967, 0.0734999857226017,
0.220321023927838, 0.168970847093894, 0.329637479054441, 0.932333806354766,
0.920347276344009, 0.0188743828318305, 0.28700830085674, 0.122086809397366,
0.721930469997516, 0.269049759688981, 0.942247445889545, 0.121226461766639,
0.269410103956184, 0.543882827865607, 0.355909915494972, 0.805553875119072,
0.562638932909877, 0.545114635056338, 0.799859513505137, 0.028300052307727,
0.583254546237197, 0.256765686729071, 0.611805711034515, 0.12397867417326,
0.904971687781288, 0.383547195151525, 0.798974934455656, 0.808113210022865,
0.180237564596422, 0.523175753649262, 0.429905001793785, 0.304352173583082,
0.40672229380892, 0.216918826340633, 0.995255476036526, 0.769882865282478,
0.315877004728925, 0.473236774091463, 0.977350069130875), STAGE1 = c(0.368965432370926,
0.700308646686629, 0.37243236843735, 0.118248974397151, 0.924365141290828,
0.762350776297416, 0.697822321048335, 0.319088598768702, 0.877683213554975,
0.750204754502701, 0.504154725402079, 0.142208638643596, 0.789965310283345,
0.23064744899036, 0.356016354550943, 0.62336479144862, 0.213046955322873,
0.0244722022581561, 0.988358158842575, 0.823084572956891, 0.303622687500738,
0.96764100797214, 0.230471412999795, 0.817462150200591, 0.65596635231198,
0.91076738319561, 0.819508996182778, 0.213131722185214, 0.588018916178037,
0.123125204015868, 0.562792521212946, 0.660044396503998, 0.978415415705398,
0.0434221393194675, 0.376954390238487, 0.0621651663358314, 0.465209931429691,
0.384575866404939, 0.242944268682905, 0.0795230807069031, 0.0199700669678636,
0.32561072886232, 0.93772541505141, 0.585428916722007, 0.318073982629541,
0.32173669386666, 0.999051218264009, 0.317443552571237, 0.660217053596061,
0.823899098997627, 0.514457733357758, 0.541111096768051, 0.55508809891723,
0.984535365206941, 0.471258908268993, 0.993506687275954, 0.437682961713191,
0.131816605892007, 0.624970126586813, 0.464518729700115), VEG1 = c(0.210969928562774,
0.898985728644631, 0.22294741757493, 0.648093601120814, 0.575025933877221,
0.836263821166674, 0.365992846024045, 0.975590314436119, 0.7669346163546,
0.606281773283188, 0.727857331528672, 0.063336204942156, 0.56024387105928,
0.572624926379006, 0.928959824695475, 0.0649894364822472, 0.484687521083679,
0.0408377810735494, 0.0863494174729038, 0.38604744652937, 0.408453836726946,
0.886479379706545, 0.484111782315899, 0.931864491830317, 0.822804779811041,
0.42950876407607, 0.870394703931469, 0.643439731712405, 0.9667566201692,
0.304607549846345, 0.364859919775087, 0.103200556844174, 0.548045455964784,
0.198120269406476, 0.0343580658743184, 0.802310877023954, 0.993783336617898,
0.0816308254407008, 0.75765020441394, 0.864780385461517, 0.312678655208107,
0.74836775788609, 0.534055051243098, 0.288890283554979, 0.953079521748438,
0.731857197421753, 0.142177987385593, 0.996762443657084, 0.243292464894029,
0.491579671466928, 0.966627062162325, 0.339857447154563, 0.461728147289064,
0.634729865229662, 0.3609970911949, 0.258390752729148, 0.506726536795493,
0.672180274413292, 0.747445719779432, 0.29334486037021), VEG2 = c(0.380862280240474,
0.627729953103904, 0.878278401019092, 0.5613186824923, 0.636249763005486,
0.62292681302113, 0.720444249110863, 0.312557900422543, 0.234122422714287,
0.499639072408177, 0.855974632998296, 0.952555098662679, 0.309983642251446,
0.882338335501354, 0.361924385825836, 0.0113958292196743, 0.302133129735417,
0.0208791658903581, 0.117232590999101, 0.925267325435408, 0.0711269914368884,
0.552243014270943, 0.125495115593106, 0.661915190374669, 0.0293896936238214,
0.294418615555011, 0.308905573205888, 0.26936911134833, 0.931505940770319,
0.021435120451226, 0.227312617286182, 0.0195785283931383, 0.099692235112247,
0.0692925181417872, 0.832555037914636, 0.380793087982671, 0.68110703188308,
0.0936612801494288, 0.051047767208204, 0.273844437996178, 0.800343046949624,
0.911380903925364, 0.582479041522435, 0.748111458524328, 0.303383302981895,
0.906904782788438, 0.328934737098847, 0.69720659917789, 0.166551542287389,
0.875547286349842, 0.265071728355448, 0.698643970290581, 0.271578241223373,
0.956035715886986, 0.583251175640849, 0.268613096173177, 0.738778731483354,
0.22125582045959, 0.289055369557255, 0.697577213911879), VEG3 = c(0.413110318831049,
0.193370500853792, 0.0443323484313173, 0.312394866761789, 0.381013563679286,
0.774340211752776, 0.315822280223384, 0.499646073445189, 0.0433440470476795,
0.63592018453082, 0.375881818437784, 0.758815519342307, 0.517769074796318,
0.0878879638478763, 0.368268890348083, 0.86661723542387, 0.159257788537873,
0.302684958923527, 0.947570919817041, 0.157392788910852, 0.125769229458094,
0.348650174982873, 0.526963940972057, 0.632646354644645, 0.351109914949622,
0.836552506892888, 0.541982479414601, 0.427697355405521, 0.799356060602721,
0.205934189654569, 0.511986141383475, 0.807482528548695, 0.232665456121877,
0.933325748417277, 0.00683041685826713, 0.21579707708936, 0.92805622685536,
0.754838770281907, 0.39901873988239, 0.991423691630203, 0.73157540991456,
0.572610353705451, 0.806848128394244, 0.445431445389894, 0.26939539811961,
0.584527298222492, 0.386004220382543, 0.242375752770125, 0.558781312238412,
0.026491283834456, 0.343044539065029, 0.802187562912211, 0.885495299962394,
0.853256462542473, 0.126077883381321, 0.780548336023421, 0.840250789403559,
0.724812876802032, 0.704098036072535, 0.201989727535322), VEG4 = c(0.640799340986514,
0.987906611244886, 0.619024206202544, 0.209427026032481, 0.489727139189696,
0.687333141302772, 0.705507906383631, 0.208889941178721, 0.396874200897516,
0.712945929935184, 0.973888093276408, 0.763823354263263, 0.377489995555215,
0.0106930906722855, 0.803664402691951, 0.278756822036515, 0.0550468580770419,
0.265168521344556, 0.987573377094547, 0.734619443919844, 0.732929467499789,
0.241731972053084, 0.559823481667716, 0.155701349465554, 0.478406027901528,
0.961160568832851, 0.0998154836815058, 0.412094044212779, 0.243883425544374,
0.942308621371675, 0.939264039325847, 0.255191997669476, 0.25098970135836,
0.882652992136823, 0.287854570522429, 0.332318399664456, 0.412416503681846,
0.321868386633491, 0.415802982737621, 0.518373582745234, 0.160366074863356,
0.328725259142546, 0.740582698190321, 0.630219424448588, 0.0963326376312392,
0.841597785551852, 0.157610936357946, 0.37344035882236, 0.665277345336568,
0.472350881237637, 0.905421464878138, 0.67001107287601, 0.931361601273204,
0.478463787477743, 0.457093329803116, 0.901963213218536, 0.0989040910780277,
0.648496145325191, 0.149756719258531, 0.766506521363941), VEG5 = c(0.180283594647103,
0.787728519142257, 0.577806490890149, 0.909505719647681, 0.843259853705306,
0.19170485676349, 0.88285289130116, 0.390956223533144, 0.400453739302465,
0.138993973168619, 0.701071911445177, 0.0275528476660395, 0.196129789901458,
0.243754073834767, 0.586994020311301, 0.309287604588564, 0.54116171026274,
0.804029207727762, 0.633322226579327, 0.576488317293166, 0.657529806993353,
0.896942372401784, 0.69552906585738, 0.00605796084044197, 0.0333828607443704,
0.421697067898017, 0.344727073066524, 0.261778629704536, 0.662947164033825,
0.264729400387399, 0.361422182455181, 0.867093056031147, 0.994741928030988,
0.1442062746899, 0.757388857488693, 0.0417225005179914, 0.448764060787373,
0.844033548534798, 0.615968575276885, 0.424045632312236, 0.419379052486891,
0.47584349576189, 0.209702827083009, 0.765825214487151, 0.834675742228314,
0.1887294652982, 0.960231969290817, 0.935011727569393, 0.976674243295263,
0.820848463468705, 0.341388666484707, 0.552464582497579, 0.573838987965132,
0.698330744449092, 0.383783839725491, 0.713851582153272, 0.964603044208545,
0.70783623057194, 0.608167299267236, 0.461582775185318)), class = "data.frame", row.names = c(NA,
-60L))
Code:
library(ggplot2)
library(ggcorrplot)
library(corrplot)
#Generate correlation matrix
res <- cor(sen)
#Generate matrix graphic
ggcorrplot(res, hc.order = FALSE, type = "lower",
outline.col = "white",
ggtheme = ggplot2::theme_gray,
colors = c("#6D9EC1", "white", "#E46726"),
lab = TRUE, lab_size = 7, show.diag=FALSE,
legend.title = "r-value", tl.cex=17)+
theme(
legend.key.width=unit(1, "cm"),
legend.key.height=unit(2.5, "cm"),
legend.title=element_text(size=20),
legend.text=element_text(size=15)
)
library(reshape2)
library(ggplot2)
res <- cor(sen)
res[upper.tri(res)] = NA
diag(res) = NA
d = melt(res)
d = d[d$Var2 %in% paste0("STAGE", 1:3),]
graphics.off()
ggplot(d, aes(x = Var1, y = Var2, fill = value, label = round(value, 2))) +
geom_tile(color = "black") +
geom_text() +
labs(fill = "r-value") +
coord_equal() #OPTIONAL
I found that another solution could be to just resize the scale to where I could crop out the unneeded variables. This isn't the most technical answer, but it works for the parameters I need:
png("wholeplant.png", width=900, height=600)
ggcorrplot(res, hc.order = FALSE, type = "lower",
outline.col = "white",
ggtheme = ggplot2::theme_gray,
colors = c("#6D9EC1", "white", "#E46726"),
lab = TRUE, lab_size = 7, show.diag=FALSE,
legend.title = "r-value", tl.cex=17)+
theme(
#resize the legend width and height
legend.key.width=unit(1, "cm"),
legend.key.height=unit(1, "cm"),
legend.title=element_text(size=20),
legend.text=element_text(size=15),
#Put it where it won't be out of the way
legend.position = c(1.1, 0.2)
)
dev.off()
I'm doing some single particle tracking experiments, and I've made a plot that looks like this
And an excerpt of the data like this
Tracks_subset <- structure(list(x = c(50.9870663039413, 51.1454673261645, 51.2438755862949,
51.2095459932038, 51.6660042216598, 50.9114140942979, 51.0024489561214,
50.8857311418507, 51.2794722111027, 51.2431331170315, 51.1686446878892,
51.6828347775235, 52.1450571292308, 52.0846161251043, 52.6398039669697,
52.8833174825244, 52.5705151101221, 47.7126603341761, 47.7043102797697,
47.7383984362003, 47.6860850023564, 47.6951829901912, 47.6699652212862,
47.7413324987855, 47.6843782373267, 47.644111020292, 47.6618622920263,
47.6541735611274, 47.6649621568611, 47.6523884564593, 47.6610279361442,
47.6512197115578, 47.6657086161767, 47.6192509459374, 47.6207586571131,
47.5774206679784, 47.6200920953012, 47.7306727739304, 47.6379509867329,
47.714775352656, 47.6550462636824, 47.6609930612728, 47.7000183950083,
47.6649651728503, 47.6539558351917, 47.6389944434634, 47.6717405874446,
47.6953802257671, 47.670156194978, 47.6659335190123, 47.6765976765644,
47.6840293686863, 47.6835120352331, 47.7206680944438, 47.6295515092937,
47.6296091556035, 47.6942899171821, 47.7250190805859, 47.5914020018512,
47.70039477981, 47.6173948003708, 47.6403690517817, 47.706224437305,
47.6278056300272, 47.7050590713087, 47.6202775363008, 47.616604053917,
47.6756516087319, 47.7266296774674, 47.6446057760854, 47.5705082443691,
47.6595393038973, 47.7454552888996, 47.6741550431176, 47.5860886147769,
47.5711827843158, 47.6032212783683, 47.6664108892973, 47.6658197925874,
48.3968244300988, 48.9904220754653, 48.8091985242839, 48.6060438195256,
47.9442329308765, 47.5918680853048, 61.7398341199382, 61.5105531711929,
61.3508575465536, 60.7780284493327, 60.9300399030291, 61.5425582885666,
61.6082571595723, 61.5298863337404, 61.7856612691648, 61.9071110539638,
62.2590343816915, 62.4185223478263, 62.9672715597194, 63.3275273995809,
63.8113387354958, 64.3231547762155, 63.7003651772996, 64.5725239608709
), y = c(25.4839360156051, 25.6047955465986, 25.4262289850266,
25.6172499551253, 25.2123769606517, 25.0385424557608, 24.966470254684,
25.0765695667183, 25.3864947576636, 25.5754234194841, 25.362590160186,
25.7772644867977, 25.5496302761478, 25.2288998273316, 25.0558763011072,
24.9078484752662, 24.976087151153, 25.3889343715977, 25.4338531136808,
25.4429033909954, 25.4318520315956, 25.3990616319309, 25.4511690945816,
25.3200107971065, 25.481502531704, 25.4813627020502, 25.4853491195569,
25.4847769218943, 25.4575428518825, 25.4557467653372, 25.4624512146039,
25.4595647154719, 25.4563293549661, 25.4804991266559, 25.3812415821813,
25.4473050286014, 25.4196869940826, 25.4442315703239, 25.479341197772,
25.4300738230213, 25.4693914326269, 25.4567345365435, 25.4674089428837,
25.4112535933299, 25.4637733103663, 25.3956145368333, 25.4990099732346,
25.4839175917237, 25.4745320245195, 25.4005315613532, 25.469591766703,
25.4539955232768, 25.4657553925353, 25.4245323404107, 25.4361711386943,
25.3891764540008, 25.466965662987, 25.1009694093232, 25.0358862503509,
25.1789725026332, 25.42714785297, 25.4795979566479, 25.468929968642,
25.4239887143419, 25.5281893742505, 25.4093001632827, 25.4384275123265,
25.4344555350342, 25.4429352491382, 25.5199514977758, 25.4910332653875,
25.4595502380103, 25.4968060944952, 25.4827240176748, 25.3698050293595,
25.4439838950347, 25.3741755234997, 25.5563892658156, 25.6960651973953,
25.7204681252841, 26.4352696253167, 27.1441226535699, 26.6615707288907,
26.3571435264103, 26.2462341038955, 25.4044026980314, 24.9429648374475,
25.316181029454, 25.5746195865509, 25.4159071371913, 25.0535276243763,
25.1404356519081, 24.9217292382466, 25.0681095303721, 25.6848864023155,
25.7992168557371, 25.2353282682059, 24.9773329424632, 24.4822347858453,
24.268105758617, 24.6415345738956, 24.0369860755695, 23.6865149091661
), steplength = c(0, 0.199243343862037, 0.203887720506984, 0.194081250972988,
0.610144455009775, 0.774354373270278, 0.116110930731278, 0.160452194371228,
0.501084477506786, 0.192391707241276, 0.225491734526058, 0.660565095527355,
0.515234739003464, 0.326375758563115, 0.581524445214716, 0.284975559445094,
0.320159087122816, 0, 0.0456882566850305, 0.035269107279719,
0.053468008239723, 0.0340291594490852, 0.0578888895422253, 0.14931773938219,
0.171240673444157, 0.0402674598162118, 0.0181933826629311, 0.00770999306101455,
0.0292931453981066, 0.0127013333423588, 0.0109357326776552, 0.0102241452834658,
0.0148457372554814, 0.0523688169390838, 0.0992689947975958, 0.079009874415496,
0.0508291898464581, 0.113271897260304, 0.0991464359452704, 0.091264765459093,
0.071508310668843, 0.0139843276580312, 0.0404588633537657, 0.066197822223741,
0.0536612168447871, 0.0697815280139674, 0.108457024734435, 0.0280466126241494,
0.0269135765181205, 0.0741208441744882, 0.06987872508325, 0.0172763670024788,
0.0117712428774199, 0.055496961741496, 0.0918569197986897, 0.0469947200495333,
0.101167000316718, 0.367284003435199, 0.148624834100549, 0.179869678487995,
0.261686837845756, 0.0572610653386249, 0.0667138499153149, 0.0903837688578274,
0.129714577882537, 0.146022440613998, 0.029358081257867, 0.0591809963859102,
0.0516785162644559, 0.112514101125709, 0.0795406083136827, 0.0944336305219004,
0.0936459039218517, 0.0726775751944748, 0.143200536740801, 0.0756616672734531,
0.0768093343124944, 0.192859469091138, 0.139677182309732, 0.731411842228994,
0.929139036438272, 0.731651960406345, 0.523572529910693, 0.728470709050467,
0.369407477451884, 0, 0.515261732169024, 0.405947063673079, 0.628429520644252,
0.219766065707624, 0.711686506777716, 0.108946532303133, 0.232324087684107,
0.294699860051154, 0.628620521453137, 0.37002902748092, 0.586009172701016,
0.606372233581375, 0.61229605162923, 0.529079057477617, 0.633565102904463,
0.867954936241549, 0.939942010041431)), class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -103L), .internal.selfref = <pointer: 0x0>, .Names = c("x",
"y", "steplength"))
And the code for the plot is
ggplot(data = Tracks_subset, aes(x = x,
y = y)) +
# stat_bin2d(bins = 10, aes(fill = ..density..)) + # blocky heat map
stat_density2d(aes(fill = ..level..,
alpha = ..level..),
bins = 20,
geom = 'polygon') +
xlim(-20,max(Tracks_subset$x)+20) + # Adds padding for polygons to have proper shape
ylim(-20,max(Tracks_subset$y)+20) +
coord_cartesian(xlim = c(0,max(Tracks_subset$x)), # Clips extra padding visually only
ylim = c(0,max(Tracks_subset$y)),
expand = FALSE) +
scale_fill_continuous(low = "white",
high = "red") +
theme_classic(base_size = 12,
base_family = "Droid Sans") +
theme(axis.text = element_text(color = "black"),
strip.text.y = element_blank(),
strip.background = element_rect(color = "white"),
legend.text = element_text(size = 12, family = "Droid Sans"),
legend.title = element_blank(),
legend.position = "none") +
facet_wrap(condition + lipase ~ video,
scales = "free")
Now my question is, how can I somehow incorporate the steplength parameter as either an extra dimension (e.g. instead of ..level.. I could somehow use steplength) or weight in the stat_density2d? I know it's possible for the stat_bin2d, but this gives me a very blocky appearance that I don't really like.