Incorporating an extra dimension in stat_density2d - r

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.

Related

loess() doesn't smooth subsequently but over pooled data

I have time-series of 2d obsverations that I'm trying to smooth to take out some of the observation variability. I've been applying loess(), but just noticed it doesn't seem to smooth as a function of time but just across the entire pooled coordinates. Am I missing something? Is there a different function I should be using?
df<-structure(list(timestamp = structure(c(1586488380, 1586488440,
1586488560, 1586488620, 1586488680, 1586488740, 1586488800, 1586488860,
1586489520, 1586489580, 1586489700, 1586489820, 1586489880, 1586489940,
1586490000, 1586490060, 1586490120, 1586490180, 1586490240, 1586490300,
1586490360, 1586490420, 1586490480, 1586490540, 1586490600, 1586490660,
1586490720, 1586490780, 1586490840, 1586490900, 1586490960, 1586491020,
1586491200, 1586491260, 1586491320, 1586491380, 1586491440, 1586491500,
1586491560, 1586491620, 1586491680, 1586491740, 1586491800, 1586491860,
1586491920, 1586491980, 1586492040, 1586492100, 1586492160, 1586492220,
1586492280, 1586492340, 1586492400, 1586492460, 1586492520, 1586492580,
1586492640, 1586492700, 1586492760, 1586492820, 1586492880, 1586492940,
1586493000, 1586493060, 1586493120, 1586493180, 1586493240, 1586493300,
1586493360, 1586493420, 1586493480, 1586493540, 1586493600, 1586493660,
1586493720, 1586493780, 1586493840, 1586493900, 1586493960, 1586494020,
1586494200, 1586494260, 1586494320, 1586494380, 1586494440, 1586494500,
1586494560, 1586494620, 1586494680, 1586494740, 1586494800, 1586494860,
1586494920, 1586494980, 1586495040, 1586495100, 1586495160, 1586495220,
1586495280, 1586495340, 1586495400, 1586495460, 1586495520, 1586495580,
1586495640, 1586495700, 1586495760, 1586495820, 1586495880, 1586495940,
1586496000, 1586496060, 1586496120, 1586496180, 1586496240, 1586496300,
1586496360, 1586496420, 1586496480, 1586496540, 1586496600, 1586496660,
1586496720, 1586496780, 1586496840, 1586496900, 1586496960, 1586497020,
1586497080, 1586497140, 1586497200, 1586497260, 1586497320, 1586497380,
1586497440, 1586497500, 1586497560, 1586497620, 1586497680, 1586497740,
1586497800, 1586497860, 1586497920, 1586497980, 1586498040, 1586498100,
1586498160, 1586498220, 1586498280, 1586498340), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), easting = c(740.582355718548, 740.582355718548,
739.726374785548, 739.611045841548, 739.508690311548, 739.398269506548,
739.278804356548, 739.627760514548, 737.913640733548, 738.088450601548,
738.551491861548, 738.957133488548, 739.137345557548, 739.304664573548,
739.460440784548, 739.605842807548, 739.741887116548, 739.719077482548,
739.369420509548, 738.973489249548, 738.521335985548, 739.279305656548,
739.993757669548, 740.085239162548, 740.172262825548, 740.255157063548,
740.334219013548, 740.409718260548, 740.481900024548, 740.550987811548,
740.573883125548, 740.252267406548, 739.261723439548, 738.935233921548,
738.774921432548, 738.615895069548, 738.451107559548, 738.280235586548,
738.493740162548, 738.717501067548, 738.925752666548, 739.120074872548,
739.301840012548, 739.472245999548, 739.632343117548, 739.890965132548,
740.098495936548, 740.293354354548, 740.476683179548, 740.649491986548,
740.678160672548, 740.443560695548, 740.398855065548, 740.451032168548,
740.467918582548, 740.160041067548, 739.819912921548, 739.641686751548,
739.457020461548, 739.265544595548, 739.193281488548, 739.227252654548,
738.995761471548, 738.822890745548, 738.775446949548, 738.726816309548,
738.676941805548, 738.625762928548, 739.254178659548, 739.727445331548,
740.019566884548, 740.129316037548, 740.255273807548, 740.442527947548,
740.615257127548, 740.775140223548, 740.923607252548, 741.055065964548,
741.139279130548, 740.907234314548, 739.290829342548, 739.115359714548,
740.664354207548, 740.589899151548, 740.578913554548, 740.571708783548,
740.568311076548, 740.568740893548, 740.527920123548, 740.358565457548,
740.392277156548, 740.370981239548, 740.289917518548, 740.214089159548,
740.192635592548, 740.176850935548, 740.160315351548, 740.143068630548,
740.103174446548, 740.008327647548, 740.058271768548, 740.205384482548,
740.211048172548, 740.150159818548, 740.122028309548, 740.230164637548,
740.271076846548, 740.075087486548, 739.768752873548, 739.586722485548,
739.940259334548, 740.233576255548, 740.473614136548, 740.495703912548,
740.341935547548, 740.186820856548, 740.204435025548, 740.299218490548,
740.318343269548, 740.238895133548, 739.999671854548, 740.062183564548,
740.196345466548, 740.329697802548, 740.418193609548, 740.311257937548,
740.270203214548, 740.209679752548, 740.146590442548, 740.079785501548,
740.170176300548, 740.268945921548, 740.217498771548, 740.133923060548,
740.117921377548, 740.177771453548, 740.140658663548, 740.080204534548,
740.108449333548, 740.145621912548, 740.182429420548, 740.010376475548,
739.819150336548, 739.616854492548, 739.369690457548, 739.104183601548,
738.938020260548, 738.843359187548, 738.802644324548, 738.761524527548
), northing = c(2307.15134120986, 2307.15134120986, 2307.60836846986,
2307.72110371186, 2307.83015111886, 2307.94605545486, 2308.06963872386,
2307.94323643186, 2308.11539257586, 2307.98516105286, 2307.67209087786,
2307.39795736686, 2307.27544716286, 2307.16124100486, 2307.05447137086,
2306.95438746086, 2306.86033624586, 2306.85049579286, 2307.02449397686,
2307.22230535086, 2307.44905018086, 2306.99878407786, 2306.57790074586,
2306.51052483586, 2306.44607531386, 2306.38433869586, 2306.32512182186,
2306.26824947086, 2306.21356227886, 2306.16091500786, 2306.12077142386,
2306.17964098286, 2306.35042514386, 2306.42512419786, 2306.46180283886,
2306.49818722086, 2306.53588972286, 2306.57498431686, 2306.47587680786,
2306.37665531786, 2306.28431106486, 2306.19814347186, 2306.11754401386,
2306.04198150286, 2305.97099021786, 2305.88981694586, 2305.83737042086,
2305.78847203986, 2305.74280289286, 2305.70008126986, 2305.72436278986,
2305.79211047386, 2305.75001607586, 2305.66373079386, 2305.59454921786,
2305.66723079486, 2305.74826733386, 2305.75631243686, 2305.76412484986,
2305.77169383886, 2305.76318962486, 2305.74988901286, 2305.84052390686,
2305.91140100786, 2305.95786180686, 2306.00518488486, 2306.05340722986,
2306.10256811686, 2305.87083530186, 2305.67745118186, 2305.55808577486,
2305.51324056486, 2305.46177226186, 2305.38525730986, 2305.31467748186,
2305.24934676386, 2305.18868082786, 2305.13496475486, 2305.08628958686,
2305.07937405386, 2305.33244795286, 2305.26640414086, 2304.97847050686,
2304.88865807586, 2304.78121096686, 2304.67333694586, 2304.56517670086,
2304.45687199986, 2304.26299422086, 2303.81398617786, 2303.81772073686,
2303.82576399386, 2303.82937144386, 2303.85166918186, 2303.85679798586,
2303.85841996086, 2303.85934299186, 2303.85962745886, 2303.81418344986,
2303.71268455886, 2303.70396413486, 2303.71187848686, 2303.71241867586,
2303.72409686386, 2303.75626565486, 2303.81432053886, 2303.80604508386,
2303.57280991386, 2303.21896587386, 2303.06912105986, 2303.28351126486,
2303.45378473786, 2303.49375232686, 2303.50460433986, 2303.48302188886,
2303.48174695086, 2303.52692291386, 2303.61686633486, 2303.41139580686,
2303.32679365886, 2303.06984393086, 2303.15017783486, 2303.29293566086,
2303.44528532286, 2303.48203523086, 2302.89274879786, 2302.81440275486,
2302.73512963586, 2302.65410710886, 2302.56757728186, 2302.77320543086,
2303.00846800486, 2303.01932301786, 2302.97477011386, 2303.03742546386,
2303.13970331386, 2303.07628123386, 2302.97297111586, 2303.02123867886,
2303.08476293486, 2303.14766331986, 2303.17026860886, 2303.18249014186,
2303.19025912386, 2303.15218828686, 2303.11064943486, 2302.98849464786,
2302.87632040886, 2302.82807292386, 2302.77934558786)), row.names = 5905:6054, class = "data.frame")
df.fitted<-loess(northing ~ easting, span = .5, data = df)
df$northing.fitted<-df.fitted$fitted
ggplot(df, aes(x=easting,y=northing)) +
geom_path(color='orangered2') +
geom_point(aes(y=northing.fitted))
So, instead of smoothing the "cluster", I'd like to use a rolling average smoothing each x/y pair as a function of time.
You need to regress both easting and northing as functions of time to get smoother x, y values:
df$numtime <- as.numeric(df$timestamp)
df.fitted.northing <-loess(northing ~ numtime, span = .5, data = df)
df.fitted.easting <- loess(easting ~ numtime, span = .5, data = df)
newdat <- data.frame(numtime = seq(min(df$numtime), max(df$numtime), len = 1000))
newdat$northing <- predict(df.fitted.northing, newdat)
newdat$easting <- predict(df.fitted.easting, newdat)
ggplot(df, aes(easting, northing)) +
geom_path(aes(color = "original path"), alpha = 0.6, size = 0.5,
arrow = arrow(length = unit(0.1, "inches"))) +
geom_point(aes(color = "original path"), alpha = 0.6, size = 1) +
geom_path(data = newdat, size = 1, aes(color = "smoothed"),
arrow = arrow(length = unit(0.1, "inches"))) +
coord_equal() +
theme_light() +
scale_color_manual(values = c("original path" = "orangered2",
"smoothed" = "deepskyblue4"), name = "")

How to specify x/y axis label values outside chart

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 to remove individual attributes within cluster plots

I would like a fairly plain, publication-quality cluster plot. I have created the plot and removed the title, legend and adjusted the axis titles, with the script provided. However, I would also like to remove all of the individual row labels 'attributes' that are my sample ID's within each of the two cluster's e.g. CLR45, HTR132. Is this possible?
fviz_cluster(k2, data = Chem)+ theme(legend.position = "none")+labs(title = "") + theme(
axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm")),
axis.title.y = element_text(margin = unit(c(0, 3, 0, 0), "mm")))
dput(head(Chem,50))
structure(c(0.147411356827536, -0.94833184269442, -0.236098761737746,
-0.156408346996621, -1.07782876612066, 0.15737266025443, -0.85369947703763,
-0.684357344128487, -0.744125156240499, -0.166369650423515, 1.06883177595158,
-1.72531338325188, -1.16249983257523, -0.908486633211519, -1.30693870691714,
-1.04296420835121, 0.336676092365792, -0.45026675161856, -0.455247403332007,
-0.935222767283235, -0.798912316639064, 0.185622913832727, -0.345812539076084,
0.264855107585394, -0.649213869051943, -0.745838498773852, -0.952615203252478,
0.510998876988382, 1.40751604176986, -0.749105803729271, 0.222121124079889,
0.146973059409158, -0.25104071265341, -0.176330949625734, -0.734163852813605,
1.1584834941196, 0.869605741211104, 0.202198517226101, 0.301811538821014,
-0.0567953296263845, -0.669415393212821, -0.191272904766074,
-0.71922190189794, 0.222121124079889, -0.51999586293279, -0.231118110024299,
0.5608053856735, -0.285905270422864, -0.614628232814256, 0.0378370402550813,
1.21148988263212, -0.722729092058211, 0.938866964062205, 1.29275958711264,
1.23956487191698, 1.86977449177269, 1.84761002727152, 2.09068032585176,
0.430561900436177, -0.339283848035902, 3.19668712695198, -0.305298335931744,
-0.0186379222283033, 3.76926913851535, -0.987963856121806, 0.356680351444172,
3.44123505721924, 0.255462628028634, -1.00052371956831, -0.425184448439876,
-0.0334142322231424, -0.313100227585446, -1.0460909046001, 0.779075947446034,
-1.04523092273039, -0.432924280356334, -0.788096532267007, 0.836910424803157,
0.471935569011041, -0.841678386878241, 3.4264587472244, 0.770476135624245,
1.97394747659788, 0.635952609659098, -0.86162640581326, -0.502562073822641,
0.695796664499772, -0.659190958982183, 0.126169915328244, -0.127243800150166,
-0.945851372685624, -0.589742302104659, -0.506994966919312, -0.665840298627189,
-0.90004481199628, -0.82320799963024, -0.566839021759986, -0.759669866554213,
-0.980575700633291, 0.208917251495781, -1.23882313589815, -0.816688277463794,
0.346387764578252, 0.524062438145321, 1.46662027130976, -0.917496601945682,
1.0860688452788, 2.10423292402831, 0.254400170526879, -0.804087236829436,
-0.843150462529107, -0.300045614716482, 0.672754716385498, -0.9527795153661,
-0.622632253058524, 0.0175006072532231, 0.578246912369032, 1.71864108103204,
-1.24512365636358, 2.67546329317061, -1.0435070073998, -1.24421134102627,
1.42382713735224, 2.28432699595981, 0.587773297320356, 0.00106885031820219,
0.211304610661984, -0.589869547527789, 0.65259305148912, 0.00867987889811877,
-1.54754862951275, 0.235750629237659, -0.331548216154132, 1.18561706626058,
-0.368091233667634, -1.09769148192, -1.03846659132395, -0.70957943281297,
-0.316426967333605, -1.05358783984799, -1.19471949412263, -0.788965988305396,
0.663933988919855, 0.346387764578252, 0.137210492538405, 0.146031220893509,
-0.456298517515165, -0.534424969210994, 0.450976402525343, 0.193915175837746,
1.53543257619906, -0.518118831649496, -0.16974850422888, 0.380309904408398,
-0.518118831649496, -0.114742659464473, 3.20394309995186, 1.0953858473389,
0.893697766122234, 0.710344953491444, -0.316430750432833, 0.453651027510375,
-0.444777708547519, 1.99381459314849, -0.664801077853449, 1.99381459314849,
0.343639347733259, 0.105280700089759, -0.811483324057402, 3.43885470777859,
-0.829818602394972, 0.948923628687728, -1.17727227024187, 0.507850124084635,
-0.054162900383238, 0.0383202589981529, -0.111075611598317, 0.215292379866875,
-0.243089627330857, -0.609795233089042, -0.499783553311926, -0.367182807190326,
-0.719806922617856, 0.105280700089759, -0.353101307107973, 0.728680241580711,
-0.848153880732542, -0.994836126936495, -1.26986533125513, -0.976500848598925,
0.398645192497665, -1.01317140527406, 0.123615978427329, -0.774812757630565,
-1.08651252837604, -0.646465799515879, -0.536454109987066, -0.829818602394972,
0.508656872274782, -0.518118831649496, 0.675002376238412, -0.0617082448613822,
-0.668996727923662, -1.60481832778947, -0.71877447345135, 0.625224632383091,
-1.78899598306442, -0.793441090906698, -1.09210755738336, 1.32211305639179,
-1.96321808990278, -1.51521838684306, 0.00549171084843096, -2.9911285157337,
0.276780418706376, -2.1225068715777, -1.56499613237074, -0.683930051414732,
0.271802645324263, 0.398636337390084, -0.270774772063992, 0.662607717406351,
1.26287754043467, -0.00695272427921605, 0.459290519580567, -0.0828886740640689,
-0.779976209944577, 0.525669143000081, 1.64566839646848, -0.527130156430866,
-1.99806251026703, 0.852509813910332, -1.05477425032805, 0.0726916665582448,
0.177224929323366, 0.824335611149109, -0.444996877229983, -0.0218860477702858,
-1.2713074392762, -0.270774772063992, -0.0467749213703124, 0.625224632383091,
-0.569441240213019, 0.722291233402677, 0.401224781689411, 0.127447185468045,
0.80442451260356, -0.594330112140679, 0.824335611149109, 0.276780418706376
), .Dim = c(50L, 5L), .Dimnames = list(c("CLR16", "CLR36", "CLR52",
"CLR56", "CLR20", "CLR22", "CLR11", "CLR14", "CLR17", "CLR33",
"CLR41", "CLR43", "CLR50", "CLR32", "CLR35", "CLR37", "CLR45",
"CLR48", "CLR49", "CLR5", "CLR55", "CLR58", "CLR59", "CLR6",
"CLR60", "CLR61", "CLR62", "CLR65", "CLR66", "CLR67", "CLR68",
"CLR7", "GGR70", "GGR77", "GGR71", "GGR69", "GGR72", "GGR73",
"GGR74", "GGR75", "GGR76", "GGR78", "GGR79", "GGR80", "GGR81",
"GGR83", "GGR84", "GGR85", "GGR87", "GGR89"), c("X88Sr_umol_molCa",
"X138Ba_umol_molCa", "X25Mg_umol_molCa", "X55Mn_umol_molCa",
"X7Li_umol_molCa")))
You can use labelsize = 0 as shown in the following code
library("factoextra")
# Data preparation
data("iris")
head(iris)
# Remove species column (5) and scale the data
iris.scaled <- scale(iris[, -5])
# K-means clustering
km.res <- kmeans(iris.scaled, 3, nstart = 25)
# Visualize kmeans clustering
fviz_cluster(km.res, iris[, -5], labelsize = 0) +
theme(legend.position = "none") + labs(title = "") +
theme(axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm")),
axis.title.y = element_text(margin = unit(c(0, 3, 0, 0), "mm")))
To remove all the little geometric shapes use geom = NULL like
fviz_cluster(km.res, iris[, -5], geom = NULL, labelsize = 0) +
theme(legend.position = "none") + labs(title = "") +
theme(axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm")),
axis.title.y = element_text(margin = unit(c(0, 3, 0, 0), "mm")))
To remove cluster centers use show.clust.cent = F
fviz_cluster(km.res, iris[, -5], geom = NULL, labelsize = 0, show.clust.cent = F) +
theme(legend.position = "none") + labs(title = "") +
theme(axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm")),
axis.title.y = element_text(margin = unit(c(0, 3, 0, 0), "mm")))

How to increase the size of text inside yellow circle of PCA Biolot using ggplot2?

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.

Is there a way to split a correlation matrix to only display a certain section of it (R)?

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()

Resources