factoextra variable plotting and labeling subset - r

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

Probably the simplest method, given your particular colour scheme, is to make the arrows all black but use the alpha channel to make the gray ones gray. This means the black arrows will still be completely black even if other arrows are drawn over the top:
fviz_pca_var(pca,
axes = c(1,2),
select.var = list(contrib = 200),
alpha.var = ifelse(markers_vec == 0, 0.2, 1),
label = "none") +
theme_bw()

Related

Svm Multi-Classification in R

I am using the SVM model for the classification of the data given below, but I don't know why I am getting this error. I have tried using two methods but both are not working. Please help me I am stuck for a very long. I have seen many posts here and tried to specify my model for classification but no results.
My data:
structure(list(pCAMKII_N = c(-0.145868903106222, -0.0757245672281776,
0.23642582674556, 0.148460249143042, -0.00305230227892469, 0.0585561745843138,
-0.148682825543474, -0.21730129212525, 0.459967321113158, 0.422894418061546,
-0.0575744512697957, -0.127564153510276, -0.242697988154887,
-0.095402375827381, 0.0140296834402993, -0.0497934688280284),
pCREB_N = c(-0.0825121744625299, -0.026500034184616, 0.0674710705932882,
-0.171872159375326, 0.0599673008600893, 0.20274815322096,
-0.138321776880784, -0.179229652914255, -0.031683391484602,
-0.107073356219089, 0.0795112065683711, 0.0230878800052553,
-0.101810049763974, 0.141596706516054, 0.175052271845758,
0.0962492148671607), pMEK_N = c(-0.011827795918493, 0.0651085636651456,
0.0372073300493682, -0.0758375679929981, 0.038855171657283,
0.162735732819232, -0.129245969397597, -0.10183076411972,
-0.030313508584495, -0.0402009321267793, 0.0265091904210039,
0.0384635318143068, -0.145082961476379, -0.00383809286152744,
0.00274224616628268, 0.0325875706999738), pNR2A_N = c(-0.040694436939677,
-0.126422726919893, 0.327029496785507, 0.11289764061805,
0.00949037400844992, -0.0370143413154391, -0.0445050341199518,
-0.0875679863319538, -0.0318024269145471, -0.0990796159280345,
0.114103842731325, 0.0684955162565601, -0.0517765103296767,
0.0262937180568668, 0.0186704564656926, -0.069607116867091
), pPKCAB_N = c(-0.0732668154024626, 0.259508683035786, -0.156388727351903,
-0.128555140589917, 0.233485439385613, -0.109922421599626,
-0.230899862755971, -0.275680739843144, 0.202586893320354,
0.128569221313288, -0.187404269824716, -0.123823456903658,
-0.0510954627942524, 0.224263475958852, -0.110903224987034,
-0.0622911739357286), pRSK_N = c(-0.0830647198678661, 0.171345235902955,
-0.00771685629829743, -0.153792422272828, 0.0775638466765593,
0.0562653498716256, -0.138802407016646, -0.115702091265824,
0.161592613345935, 0.120453263851679, -0.0389173648044295,
-0.0711265266002543, -0.207578315767319, -0.0270749356104633,
0.0589442953743869, 0.0144541906539012), AKT_N = c(0.0481798874438209,
-0.0923315388558725, -0.108885641561443, -0.105416833062579,
0.144880510212411, 0.00523331467580219, 0.0328578246677392,
0.0571445022606188, -0.0209256486347021, -0.0730029998614634,
0.0440023583125468, 0.0717278333163182, 0.0196560602422922,
0.0988713938163715, 0.0527286790966814, 0.0229037502299382
), BRAF_N = c(-0.00321939692704801, 0.0962073093317588, -0.0677402898524546,
-0.067209980101031, -0.0192180601759131, 0.0499710838529006,
-0.0685860451987449, -0.0621210254646294, 0.0464452196252293,
0.0717595906404571, -0.0808646010953599, -0.070139309127312,
0.0260226905885634, 0.0307477583500104, -0.0495839406552054,
-0.0605696564634389), CREB_N = c(0.0633377024959499, 0.0719351180508572,
0.0554860017614535, -0.0754709592333137, -0.051730811130647,
0.0770585706175764, -0.119490365368989, -0.101979827161643,
0.0390935428793637, 0.0334190803939948, -0.0231648718807617,
0.175244016989004, -0.199464488371739, -0.0830526740916612,
-0.0236000029056659, -0.0555939459680455), ERK_N = c(0.113758147959477,
-0.0935376622896181, -0.194533549084613, -0.202343017546552,
0.368811506067506, 0.0211924441765911, -0.166177103411079,
-0.239377414372715, 0.0512242092661902, -0.030723497203822,
0.00664926832340125, -0.105494671248667, 0.143740808738886,
0.306473059519756, 0.068383724577022, 0.0171957013321164),
GSK3B_N = c(0.0496851372868314, 0.0965673122890421, -0.122194260011564,
-0.113614901308566, 0.147165890990766, -0.0568100186969033,
-0.150554531109297, -0.188598927874271, 0.0729314311629536,
0.0534454310403283, -0.0530979322493377, -0.108715383018256,
0.0774398337859832, 0.133178525946526, 0.00917139328707758,
0.00415362892452407), JNK_N = c(0.084671436503407, 0.091451395958942,
-0.0735719764555032, -0.128089296490928, 0.0482424225269525,
0.136559678562216, -0.0983547253737015, -0.0994914255127194,
0.00287013911408683, -0.0207264777165356, -0.0425235674499462,
-0.0328911666055918, -0.102415581508767, 0.0426548346554378,
-0.0453706640514963, 0.0837146521123543), MEK_N = c(0.0415145904202766,
0.000112891679066114, -0.0947656593375573, -0.161573116350825,
0.217458153608386, 0.132508968100251, -0.177468380610068,
-0.18842935475728, 0.00445721815704893, -0.0539245065836939,
-0.00307155552655238, 0.0116656936964918, -0.100533579935951,
0.19149971269713, 0.15252996223312, 0.0956503457831564),
RSK_N = c(0.0191395815813382, 0.0714942086955356, 0.0161998863368589,
-0.184560332102979, -0.0264979202843543, 0.298908704096619,
-0.0968942910305665, -0.0189051673871464, 0.0861641375591587,
0.0160470100470935, -0.0682290713635209, -0.0518589639648677,
-0.23241046414349, -0.0542963774080875, -0.0873418795312474,
0.0210347924349621), APP_N = c(-0.0806791681338731, -0.0704201146133004,
-0.190200351582733, -0.162718360121692, 0.0303369406177179,
-0.0860104704967967, -0.162468694656265, -0.186756215303488,
0.149403011555697, 0.0234829670280346, 0.0759128457278766,
0.0934903179979386, 0.105907786308873, 0.361038543968712,
0.0786334044736174, 0.0784404724592734), Bcatenin_N = c(-0.0609377198837611,
-0.111471497502357, -0.0866850028872295, -0.134271109042703,
0.197879694030571, -0.025717790316679, -0.114779722205815,
-0.215166874658, 0.093663448787465, -0.0106410825979063,
0.0856165346234392, -0.0915811784652404, -0.0313801262102451,
0.220238809782054, 0.13789742580927, 0.141644968613549),
SOD1_N = c(-0.123838690502292, -0.144130158837663, 0.0727560720797953,
-0.0681671745118475, -0.123567494179754, -0.117023734873497,
0.253293745880715, 0.185224720298962, -0.11802985927293,
-0.143547249900102, 0.47503997511273, 0.434217391632064,
-0.15212803487222, -0.106940962031447, 0.100783205025425,
0.363303202025603), P38_N = c(0.0135880916776172, -0.0645721208196919,
0.0948843285406695, 0.159312513843406, -0.0770493007707386,
-0.107486334544236, 0.150819778231829, 0.217491472288877,
-0.121236098381148, -0.130587965985436, 0.0116164053669351,
0.144776197754908, -0.158244000282848, -0.13848656873568,
0.0539113322660321, -0.0721957070846476), DSCR1_N = c(0.0873105225377593,
-0.0399938541478373, -0.0423959808617725, 0.0615326056646092,
-0.0290529787358271, 0.0522204008570095, -0.0475227862097225,
0.0308446987929902, -0.0305665225181376, -0.0607456490874483,
0.0279790218604084, 0.100583918291236, -0.0206748799372295,
0.010415281028328, -0.0414425004790977, -0.0489198196614915
), NR2B_N = c(0.106299550498296, -0.0381078612482542, -0.00101679889831333,
0.0267320329216243, 0.112439396399247, -0.064052196844109,
-0.00641666140192624, 0.0613191854808411, 0.0168607292707449,
-0.0487573287523953, -0.0439584530719966, 0.00809905456774659,
-0.0667726467406412, 0.0694971401183639, -0.000212905759537097,
0.0163350414150324), pNUMB_N = c(0.202564418361944, -0.00200124352888242,
-0.0998561853278869, 0.037524195854859, 0.149886434896155,
0.195128273020257, -0.195094705493063, -0.140281085662283,
0.0590093896988644, 0.00582004770130322, -0.0546687365873218,
0.0551625036706637, 0.0777195935539914, 0.036101539026412,
0.0107519309923, -0.103469871374173), TIAM1_N = c(0.058847821102376,
-0.159760016471791, -0.0979806570256097, 0.0531257042802172,
0.103564419565561, -0.0238368367628548, -0.0729210307202995,
-0.06325777516333, -0.0281144756311353, -0.0884600747007959,
0.00512281704622422, 0.0615056543435742, -0.00313409869767671,
0.0899369569840853, 0.120845861658354, -0.00443043623680605
), pP70S6_N = c(-0.217859954507296, 0.243521933127221, 0.0425412592499045,
0.0832466388027541, -0.0874992096268626, -0.14876403578688,
-0.00476984544201101, 0.0106283984338779, 0.114328759061199,
0.125171996276406, -0.0925437220067121, -0.0570200090555343,
-0.252313164764891, -0.183959220656612, 0.189234923062614,
0.179602221371295), NUMB_N = c(0.0507161136495314, -0.0428893884462266,
-0.0737803369486708, -0.125816787402445, 0.157329290628144,
-0.0618269592229841, -0.121271771020323, -0.208391773663935,
0.0398518709801874, -0.015557253715229, -0.0686033888733257,
-0.146899366608736, 0.229868831769603, 0.328004434107362,
0.262082754277244, 0.270980403077601), P70S6_N = c(-0.0467645544881666,
-0.0513422563937406, 0.0806193466797829, -0.097604174996586,
0.169381505159102, -0.10953472581413, -0.0762873839439222,
-0.137957724239911, -0.0404929923772219, -0.112679782727059,
0.0478687778434949, -0.135047834380878, 0.235505540876976,
0.101996139976229, 0.0881984401256723, 0.0308682316870565
), pGSK3B_N = c(0.0726318660370534, 0.0113934692941635, -0.0784493639363762,
-0.129201494480153, 0.157796847802845, 0.23002474684606,
-0.156189105610425, -0.139272331325838, 0.118225045060094,
0.100304800513178, -0.0300757618933809, 0.0285299986456296,
-0.0120541561865572, 0.0908216848045133, -0.0023908457607024,
0.0089400750177918), pPKCG_N = c(-0.286386712047411, 0.265957237376396,
0.0737964172058239, -0.0759384400199, -0.0177238455253068,
-0.261634570955355, -0.253741047251584, -0.256650485194398,
0.134270402692566, 0.120849091119421, -0.146949388514596,
-0.142381255596242, -0.324527167558674, 0.195095873727953,
0.208752130225386, 0.246345320116692), CDK5_N = c(0.0835756577065185,
0.00364250782584705, -0.0635878598042922, -0.0665527642492147,
0.0498548879577531, -0.0037462363944042, -0.0709716342392349,
-0.109665096982383, -0.00693856902849091, 0.0043142382793781,
-0.00379427922410826, 0.0233969910641444, -0.000723497291038827,
0.106033840892453, 0.029827781661049, 0.0297508490072604),
S6_N = c(0.168888926042562, 0.230803056253277, -0.154902829994192,
-0.269491504226569, 0.142290171760069, 0.252241256219668,
-0.23854742286132, -0.264415247456924, 0.290083441282089,
0.238143298906295, -0.198459186518937, -0.263240335960755,
0.238832926146062, 0.35530004861393, 0.427790444668465, 0.360513465094153
), ADARB1_N = c(0.224098318811728, 0.0338977810779033, 0.116024199822639,
-0.00457055801051897, 0.530704385640093, -0.178020136682188,
-0.113465216543545, -0.173452014027142, 0.00633272386184758,
-0.0237300986226981, 0.139970553648416, 0.00713778435199307,
0.356303393951797, 0.328108176871799, -0.103822560250247,
-0.160096407917707), RRP1_N = c(0.00159121579454942, -0.0299422881516384,
0.0173826784335047, 0.0386298578057867, -0.022152469642015,
0.0369774839239829, -0.0197907278638186, -0.0201116884888817,
-0.016726870724063, -0.0138128805216459, 0.00747529027834608,
0.0385018374429109, -0.0165448322480326, -0.00614007382478539,
-0.00733137421781927, 0.0183421735187617), BAX_N = c(0.0348507900184639,
-0.169715973558917, 0.0312101948023616, 0.0728175524004573,
0.179257945173096, -0.00628218585999311, -0.114699647957541,
-0.213302817321221, -0.0219721111119517, -0.0411959352332957,
0.0140823449452806, 0.00562779088047583, -0.0465748954281123,
0.166914376799791, 0.121181906942324, 0.0465930748380351),
ERBB4_N = c(0.226825268882082, -0.124939501170309, -0.0779332590062461,
-0.18657539448526, 0.186503290026721, -0.209722491963456,
-0.0376960514068148, 0.0222951541745705, -0.058799632488138,
-0.106621802599657, 0.037095159045507, -0.0713172478048624,
0.0826014680466721, 0.0644672868926184, -0.022902877277575,
0.0811348220744181), nNOS_N = c(-0.0597607386610167, 0.0694317666060796,
0.0267840157110256, -0.0466611419857235, -0.0427174888142891,
-0.312236651256378, -0.010954182164099, -0.152991551731999,
-0.0500742377998905, -0.112776761155327, -0.0702701990622843,
-0.158725995917858, -0.170582110044521, -0.195995554048211,
0.270601021309697, 0.164312802991015), Tau_N = c(-0.0295470448997678,
-0.0135843635099774, -0.0532058617661047, -0.0555870385379599,
0.0413976507530296, -0.134898190226349, -0.0588315550075754,
-0.0795207957893949, -0.00171411389248874, -0.0482028991095779,
-0.132181492884161, -0.16272346727488, 0.0684355887357164,
0.0845081538871629, 0.17928411442039, 0.399425311619017),
GFAP_N = c(0.1022369732202, -0.0375872399271431, 0.0389750353783662,
-0.0504675751546967, 0.0274358635290079, 0.1734228779599,
-0.0412006018348187, -0.0716080720004096, 0.00463136477041947,
0.0395185137074335, -0.0488608095557386, 0.133429595736969,
-0.0456410825935039, -0.0308800819276867, -0.0205041295367554,
0.00291773400108061), GluR3_N = c(-0.030610619693228, -0.0419884945813332,
-0.0215878967844794, 0.13788987742286, 0.0097421522245054,
-0.185481343626263, 0.039394235524668, -0.0423606094227236,
-0.0300386175931323, -0.0704781156851588, 0.149635559983053,
0.194784934048682, 0.0579351879333201, -0.029201096262343,
0.035471474252518, 0.0130390262499429), GluR4_N = c(-0.0645767955225773,
-0.051538941109314, -0.0313732251039657, -0.0141460065921882,
-0.00417582031288004, -0.029593478043205, -0.0337244128285424,
-0.0473718497413239, -0.0076614057457667, -0.0274641649555311,
0.0567450285050144, 0.131417882380042, 0.0167002653120917,
0.0102756570041332, 0.0589477012145904, 0.0282615479355968
), IL1B_N = c(0.0271273847003715, -0.105491449847318, 0.0437609140660753,
-0.100682647720751, -0.0220718458071589, -0.255060461104892,
0.136556106808522, 0.171611061468201, -0.107978458154497,
-0.138468912721386, 0.0906412612736424, 0.103367168201442,
-0.0471777535915392, -0.0996457367924041, -0.0253085398636734,
0.0972606458616279), P3525_N = c(0.282068129966564, -0.00165311433635766,
-0.0922619335624527, -0.153415327839175, 0.123335275814776,
-0.217141845924011, -0.0794347237762894, -0.0633312926140292,
-0.0550134841848069, -0.0335943662560428, -0.172561096964795,
-0.0591245566896425, -0.0903407471772672, 0.0672553394698634,
0.277963667780744, 0.280422376361652), pCASP9_N = c(-0.0809064432825608,
-0.0137019165208861, 0.177743120582825, -0.0475158803923548,
0.193740256728041, -0.234087587902465, -0.13810712700627,
-0.123144569174683, -0.159086554429722, -0.196839206663645,
0.272409729812092, 0.163528529740624, 0.094264422008515,
0.0323567060275672, 0.132123054461642, -0.0232714678908218
), PSD95_N = c(0.0540563342629853, -0.0442860567878406, 0.192681249153854,
-0.0499306400945902, -0.0256836260381356, -0.130320516544179,
-0.0318622026430037, -0.05550691698767, -0.0550237612521986,
-0.0975383913984803, 0.0610109420236561, -0.016528638117965,
-0.0355453200230897, 0.0361199546017388, -0.0438265148666351,
0.15961796487275), SNCA_N = c(0.10038812821577, -0.203187652543977,
0.132600250445984, 0.0870009029169576, -0.16121896139518,
0.00675222688338345, 0.201408060453561, 0.166171601944603,
-0.244202510820346, -0.184881118438059, 0.0158087569191595,
0.163733417301441, -0.19931602328197, -0.0822025824650802,
0.0270161636801945, -0.0311533368903992), Ubiquitin_N = c(0.113890598772724,
-0.0571595522614428, 0.251655448625955, 0.0290662757157521,
-0.113226757122626, -0.118822873950306, -0.0895156964787369,
-0.115101576386724, -0.0883300072975741, -0.0451690155410069,
0.0356232623609365, 0.10502000854939, -0.242738889727437,
-0.000642607498821009, 0.023342908881478, -0.000996135171924353
), pGSK3B_Tyr216_N = c(0.171426581336935, 0.21964402951554,
-0.146777292906524, -0.180066591627815, 0.0607373096178199,
-0.338285372919054, -0.192946966367207, -0.179745246639312,
-0.0202782074462171, -0.0754752662878523, -0.0458616948609926,
-0.0702022161357589, -0.0329854942199789, 0.103988666502327,
0.160536360262989, 0.130136693548004), SHH_N = c(0.167413839912217,
0.177150215231475, -0.11706030681231, -0.103724722509818,
-0.105962891517635, -0.163445660332417, 0.26057121922903,
0.323113244273389, -0.154575367677723, -0.203841975554592,
-0.196762498711561, -0.0810430316565208, -0.164628664080618,
-0.0670952384804719, 0.0701383687380666, 0.0664763199521191
), BAD_N = c(1.38627815493717e-17, 0.108885085055258, 1.38627815493717e-17,
0.204958164782363, -0.109706654809739, 1.38627815493717e-17,
-0.0384428632142642, 0.113022480455563, -0.0230560609956582,
0.00709971300305052, 0.0944175354012559, 0.258234547510358,
-0.172555989304076, -0.115571199147466, -0.0361880642339753,
0.0555296363853341), BCL2_N = c(0.174830527318015, -0.0351916650236411,
4.47594455930353e-17, 0.16122241936817, -0.153630588784925,
4.47594455930353e-17, 0.0259483341117695, 0.10217304978238,
-0.113426224559798, -0.0493655879422875, 4.47594455930353e-17,
4.47594455930353e-17, -0.176439561319639, 0.00332642384209326,
-0.112281307284837, 4.47594455930353e-17), pS6_N = c(0.0544957045743841,
-0.215498231280905, 0.176330539472927, -0.0180427806336791,
0.0405134698307664, -0.196511194503692, 0.0896380150212792,
-0.00178437398723737, -0.111094705650147, -0.164447287557879,
0.0171495879982054, 0.17357748138507, -0.0854290326165926,
-0.136862309389642, 0.0486149936008245, 0.0468734606012612
), pCFOS_N = c(-3.94541709971541e-17, 0.144688662108845,
-0.0523244997808654, 0.183632906884199, -0.0943286515483249,
-0.154870867441355, 0.0273962871834048, -0.0446413560661544,
-0.151142681858317, -0.142540841364996, -0.0409951996945863,
0.209594994520851, -0.07067492413067, -0.0951447007727713,
0.0510274910486943, -0.10813485862325), SYP_N = c(0.1699192032091,
-0.007408249850341, 0.105706192867166, 0.030169211570003,
0.264311270468507, -0.174104272666862, -0.0320510372603059,
-0.146577591364027, 0.0748281855773365, 0.0921704540339964,
0.125632959616699, 0.101821683371461, -0.0991623357830543,
0.24508774982114, -0.0514314977651764, -0.0356173972612358
), H3AcK18_N = c(0.00318526058246947, 0.030516867974744,
0.0458325444094067, 0.0823406614957822, 0.0655800040015427,
1.34928358031281e-17, -0.066090760307071, -0.0164952261270702,
0.0193438095162109, 0.0214199163861949, 1.34928358031281e-17,
1.34928358031281e-17, -0.18204363595328, 0.0122967495407723,
-0.0057641327038032, 0.315397204575443), EGR1_N = c(0.22091436521792,
-0.0418899558545117, 4.08083728048395e-18, 4.08083728048395e-18,
-0.132192787939268, 4.08083728048395e-18, 0.170088635236541,
0.14416021675064, -0.136632103055064, -0.105975572333308,
0.157046871143272, 0.390639305517813, -0.135156681648399,
-0.14858326296597, -0.0787741349821091, -0.00864723924102435
), H3MeK4_N = c(2.39945987461847e-17, 2.39945987461847e-17,
2.39945987461847e-17, 0.0613111993676987, -0.0735063751409676,
2.39945987461847e-17, -0.0518102234068636, -0.0134739460741966,
-0.0578126454640219, 0.0237615758984536, 2.39945987461847e-17,
2.39945987461847e-17, -0.176488012336739, -0.119630246017519,
-0.139100793400124, 0.159811180815282), CaNA_N = c(0.228323127723045,
0.156499372224674, -0.218869345925655, -0.347696517405393,
0.258547187716627, 0.0491641323435211, -0.275043873926982,
-0.280621847419711, 0.221404071790851, 0.213771806346338,
-0.138770962441139, -0.179432243201944, 0.104799593812621,
0.247597575511052, -0.0575169171888767, 0.0268368286591718
), class = c("c-CS-m", "c-CS-m", "c-SC-m", "c-SC-m", "c-CS-s",
"c-CS-s", "c-SC-s", "c-SC-s", "t-CS-m", "t-CS-m", "t-SC-m",
"t-SC-m", "t-CS-s", "t-CS-s", "t-SC-s", "t-SC-s")), row.names = c(NA,
-16L), class = c("tbl_df", "tbl", "data.frame"))
my code:
# Splitting the data
trainX <- createDataPartition(np_2$class ,p=0.8,list=FALSE)
train <- np_2[trainX,]
test <- np_2[-trainX,]
Model 1:
svm1 <- svm(class~., data = train, type = "C", kernal="radial",
gamma=0.1, cost=10)
Model 2:
x <- subset(np_2, select = -class)
y <- np_2$class
model <- svm(x, y, probability = TRUE)
pred_prob <- predict(model, x, decision.values = TRUE, probability = TRUE)
Error:
Error in svm.default(x, y, probability = TRUE) :
Need numeric dependent variable for regression.
Here you go. Next time try to include the libraries:
Just transform your class to a factor. In that case, the svm will convert it to numeric for you:
np_2 <- transform(np_2, class = factor(class))
trainX <- caret::createDataPartition(np_2$class ,p=0.8,list=FALSE)
train <- np_2[trainX,]
test <- np_2[-trainX,]
e1071::svm(class~.,data =train, type = "C", kernal="radial",gamma=0.1,cost=10)
which outputs:
Call:
svm(formula = class ~ ., data = train, type = "C", kernal = "radial", gamma = 0.1, cost = 10)
Parameters:
SVM-Type: C-classification
SVM-Kernel: radial
cost: 10
Number of Support Vectors: 16

Linear Regression Analysis of population data with R

I have a homework assignment where I need to take a CSV file based around population data around the United States and do some data analysis on the data inside. I need to find the data that exists for my state and for starters run a Linear Regression Analysis to predict the size of the population.
I've been studying R for a few weeks now, went through a LinkedIn Learning training, as well as 2 different trainings on pluralsight about R. I have also tried searching for how to do a Linear Regression Analysis in R and I find plenty of examples for how to do it when the data is perfectly laid out in a table in just the right way to Analyze.
The CSV file is laid out so that each state is defined on a single line/row so I used the filter function to grab just the data for my State and put it into a variable.
Within that dataset the population data is defined across several columns with the most important data being the Population Estimates for each year from 2010 to 2018.
library(tidyverse)
population.data <- read_csv("nst-est2018-alldata.csv")
mn.state.data <- filter(population.data, NAME == "Minnesota")
I'm looking for some help to get headed in the right direction my thought is that I will need to create to containers of data 1 having each year from 2010 to 2018 and one that contains the population data for each of those years. And then use the xyplot function with those two containers? If you have some experience in this area please help me think this through I'm not looking for anybody to do the assignment for me just want some help trying to think it through.
Edit: Here is the results of the
dput(head(population.data))
command:
structure(list(SUMLEV = c("010", "020", "020", "020", "020",
"040"), REGION = c("0", "1", "2", "3", "4", "3"), DIVISION = c("0",
"0", "0", "0", "0", "6"), STATE = c("00", "00", "00", "00", "00",
"01"), NAME = c("United States", "Northeast Region", "Midwest Region",
"South Region", "West Region", "Alabama"), CENSUS2010POP = c(308745538L,
55317240L, 66927001L, 114555744L, 71945553L, 4779736L), ESTIMATESBASE2010
= c(308758105L,
55318430L, 66929743L, 114563045L, 71946887L, 4780138L), POPESTIMATE2010 =
c(309326085L,
55380645L, 66974749L, 114867066L, 72103625L, 4785448L), POPESTIMATE2011 =
c(311580009L,
55600532L, 67152631L, 116039399L, 72787447L, 4798834L), POPESTIMATE2012 =
c(313874218L,
55776729L, 67336937L, 117271075L, 73489477L, 4815564L), POPESTIMATE2013 =
c(316057727L,
55907823L, 67564135L, 118393244L, 74192525L, 4830460L), POPESTIMATE2014 =
c(318386421L,
56015864L, 67752238L, 119657737L, 74960582L, 4842481L), POPESTIMATE2015 =
c(320742673L,
56047587L, 67869139L, 121037542L, 75788405L, 4853160L), POPESTIMATE2016 =
c(323071342L,
56058789L, 67996917L, 122401186L, 76614450L, 4864745L), POPESTIMATE2017 =
c(325147121L,
56072676L, 68156035L, 123598424L, 77319986L, 4875120L), POPESTIMATE2018 =
c(327167434L,
56111079L, 68308744L, 124753948L, 77993663L, 4887871L), NPOPCHG_2010 =
c(567980L,
62215L, 45006L, 304021L, 156738L, 5310L), NPOPCHG_2011 = c(2253924L,
219887L, 177882L, 1172333L, 683822L, 13386L), NPOPCHG_2012 = c(2294209L,
176197L, 184306L, 1231676L, 702030L, 16730L), NPOPCHG_2013 = c(2183509L,
131094L, 227198L, 1122169L, 703048L, 14896L), NPOPCHG_2014 = c(2328694L,
108041L, 188103L, 1264493L, 768057L, 12021L), NPOPCHG_2015 = c(2356252L,
31723L, 116901L, 1379805L, 827823L, 10679L), NPOPCHG_2016 = c(2328669L,
11202L, 127778L, 1363644L, 826045L, 11585L), NPOPCHG_2017 = c(2075779L,
13887L, 159118L, 1197238L, 705536L, 10375L), NPOPCHG_2018 = c(2020313L,
38403L, 152709L, 1155524L, 673677L, 12751L), BIRTHS2010 = c(987836L,
163454L, 212614L, 368752L, 243016L, 14227L), BIRTHS2011 = c(3973485L,
646265L, 834909L, 1509597L, 982714L, 59689L), BIRTHS2012 = c(3936976L,
637904L, 830701L, 1504936L, 963435L, 59070L), BIRTHS2013 = c(3940576L,
635741L, 830869L, 1504799L, 969167L, 57936L), BIRTHS2014 = c(3963195L,
632433L, 836505L, 1525280L, 968977L, 58907L), BIRTHS2015 = c(3992376L,
634515L, 837968L, 1545722L, 974171L, 59637L), BIRTHS2016 = c(3962654L,
628039L, 831667L, 1541342L, 961606L, 59388L), BIRTHS2017 = c(3901982L,
616552L, 816177L, 1519944L, 949309L, 58259L), BIRTHS2018 = c(3855500L,
609336L, 804431L, 1499838L, 941895L, 57216L), DEATHS2010 = c(598691L,
110848L, 140785L, 228706L, 118352L, 11073L), DEATHS2011 = c(2512442L,
470816L, 586840L, 962751L, 492035L, 48818L), DEATHS2012 = c(2501531L,
460985L, 584817L, 960575L, 495154L, 48364L), DEATHS2013 = c(2608019L,
480032L, 605188L, 1011093L, 511706L, 50847L), DEATHS2014 = c(2582448L,
470196L, 597078L, 1006057L, 509117L, 49692L), DEATHS2015 = c(2699826L,
488881L, 626494L, 1052360L, 532091L, 51820L), DEATHS2016 = c(2703215L,
480331L, 619471L, 1058173L, 545240L, 51662L), DEATHS2017 = c(2779436L,
501022L, 620556L, 1092949L, 564909L, 53033L), DEATHS2018 = c(2814013L,
506909L, 621030L, 1109152L, 576922L, 53425L), NATURALINC2010 = c(389145L,
52606L, 71829L, 140046L, 124664L, 3154L), NATURALINC2011 = c(1461043L,
175449L, 248069L, 546846L, 490679L, 10871L), NATURALINC2012 = c(1435445L,
176919L, 245884L, 544361L, 468281L, 10706L), NATURALINC2013 = c(1332557L,
155709L, 225681L, 493706L, 457461L, 7089L), NATURALINC2014 = c(1380747L,
162237L, 239427L, 519223L, 459860L, 9215L), NATURALINC2015 = c(1292550L,
145634L, 211474L, 493362L, 442080L, 7817L), NATURALINC2016 = c(1259439L,
147708L, 212196L, 483169L, 416366L, 7726L), NATURALINC2017 = c(1122546L,
115530L, 195621L, 426995L, 384400L, 5226L), NATURALINC2018 = c(1041487L,
102427L, 183401L, 390686L, 364973L, 3791L), INTERNATIONALMIG2010 =
c(178835L,
45723L, 25158L, 68742L, 39212L, 928L), INTERNATIONALMIG2011 = c(792881L,
206686L, 116948L, 285343L, 183904L, 4716L), INTERNATIONALMIG2012 =
c(858764L,
207584L, 120995L, 344198L, 185987L, 5874L), INTERNATIONALMIG2013 =
c(850952L,
194103L, 126681L, 329897L, 200271L, 5111L), INTERNATIONALMIG2014 =
c(947947L,
222685L, 134310L, 365281L, 225671L, 3753L), INTERNATIONALMIG2015 =
c(1063702L,
227275L, 142759L, 429088L, 264580L, 4685L), INTERNATIONALMIG2016 =
c(1069230L,
236718L, 144859L, 436795L, 250858L, 5950L), INTERNATIONALMIG2017 =
c(953233L,
215872L, 126013L, 404582L, 206766L, 3190L), INTERNATIONALMIG2018 =
c(978826L,
229700L, 127583L, 418418L, 203125L, 3344L), DOMESTICMIG2010 = c(0L,
-32918L, -50873L, 90679L, -6888L, 1238L), DOMESTICMIG2011 = c(0L,
-159789L, -186896L, 335757L, 10928L, -2239L), DOMESTICMIG2012 = c(0L,
-205314L, -181285L, 336615L, 49984L, 59L), DOMESTICMIG2013 = c(0L,
-216273L, -123814L, 293443L, 46644L, 2641L), DOMESTICMIG2014 = c(0L,
-274391L, -182730L, 373439L, 83682L, -755L), DOMESTICMIG2015 = c(0L,
-339996L, -234823L, 452879L, 121940L, -1553L), DOMESTICMIG2016 = c(0L,
-372953L, -228200L, 442633L, 158520L, -1977L), DOMESTICMIG2017 = c(0L,
-316879L, -161387L, 364465L, 113801L, 2065L), DOMESTICMIG2018 = c(0L,
-292928L, -157048L, 345132L, 104844L, 5718L), NETMIG2010 = c(178835L,
12805L, -25715L, 159421L, 32324L, 2166L), NETMIG2011 = c(792881L,
46897L, -69948L, 621100L, 194832L, 2477L), NETMIG2012 = c(858764L,
2270L, -60290L, 680813L, 235971L, 5933L), NETMIG2013 = c(850952L,
-22170L, 2867L, 623340L, 246915L, 7752L), NETMIG2014 = c(947947L,
-51706L, -48420L, 738720L, 309353L, 2998L), NETMIG2015 = c(1063702L,
-112721L, -92064L, 881967L, 386520L, 3132L), NETMIG2016 = c(1069230L,
-136235L, -83341L, 879428L, 409378L, 3973L), NETMIG2017 = c(953233L,
-101007L, -35374L, 769047L, 320567L, 5255L), NETMIG2018 = c(978826L,
-63228L, -29465L, 763550L, 307969L, 9062L), RESIDUAL2010 = c(0L,
-3196L, -1108L, 4554L, -250L, -10L), RESIDUAL2011 = c(0L, -2459L,
-239L, 4387L, -1689L, 38L), RESIDUAL2012 = c(0L, -2992L, -1288L,
6502L, -2222L, 91L), RESIDUAL2013 = c(0L, -2445L, -1350L, 5123L,
-1328L, 55L), RESIDUAL2014 = c(0L, -2490L, -2904L, 6550L, -1156L,
-192L), RESIDUAL2015 = c(0L, -1190L, -2509L, 4476L, -777L, -270L
), RESIDUAL2016 = c(0L, -271L, -1077L, 1047L, 301L, -114L), RESIDUAL2017 =
c(0L,
-636L, -1129L, 1196L, 569L, -106L), RESIDUAL2018 = c(0L, -796L,
-1227L, 1288L, 735L, -102L), RBIRTH2011 = c(12.79898857, 11.646389369,
12.449493906, 13.0753983, 13.564866164, 12.455601786), RBIRTH2012 =
c(12.589173852,
11.454833676, 12.353389372, 12.900715293, 13.172754439, 12.287820829
), RBIRTH2013 = c(12.511116578, 11.384582534, 12.318197145, 12.770698648,
13.1250523, 12.012410502), RBIRTH2014 = c(12.493440163, 11.301146646,
12.363692308, 12.814734, 12.993051496, 12.179749675), RBIRTH2015 =
c(12.493175596,
11.324209532, 12.357461907, 12.843808208, 12.92441189, 12.301816868
), RBIRTH2016 = c(12.309933949, 11.20434042, 12.242454436, 12.663079639,
12.619264908, 12.222387438), RBIRTH2017 = c(12.039095529, 10.996948983,
11.989119413, 12.357287884, 12.333939366, 11.962999487), RBIRTH2018 =
c(11.820984126,
10.863177115, 11.789576855, 12.078306222, 12.128940451, 11.720998206
), RDEATH2011 = c(8.0928244199, 8.4846099623, 8.7504877826, 8.3388830191,
6.7917918366, 10.187095914), RDEATH2012 = c(7.9990857588, 8.2779015368,
8.6968381072, 8.2343067033, 6.7700904074, 10.060744313), RDEATH2013 =
c(8.2803198685,
8.5962112289, 8.9723230665, 8.5807898649, 6.9298356343, 10.542582104
), RDEATH2014 = c(8.1408206164, 8.4020820365, 8.8249187702, 8.4524499397,
6.8267702932, 10.274434632), RDEATH2015 = c(8.4484528254, 8.7250748685,
9.2388679994, 8.7443343664, 7.0592978512, 10.689339673), RDEATH2016 =
c(8.3975028099,
8.5692003816, 9.1188486402, 8.6935469035, 7.1552465339, 10.632332792
), RDEATH2017 = c(8.5756150392, 8.9363320099, 9.1155717285, 8.8857783149,
7.3396052849, 10.889883997), RDEATH2018 = c(8.6277792774, 9.0371195009,
9.1016891619, 8.9320830002, 7.4291216994, 10.944391939), RNATURALINC2011 =
c(4.7061641498,
3.161779407, 3.6990061239, 4.7365152812, 6.7730743272, 2.2685058724
), RNATURALINC2012 = c(4.5900880929, 3.1769321388, 3.656551265,
4.66640859, 6.402664032, 2.2270765159), RNATURALINC2013 = c(4.2307967093,
2.7883713049, 3.3458740787, 4.1899087829, 6.1952166656, 1.4698283977
), RNATURALINC2014 = c(4.3526195469, 2.89906461, 3.5387735378,
4.3622840605, 6.1662812026, 1.9053150433), RNATURALINC2015 =
c(4.0447227708,
2.5991346635, 3.1185939072, 4.0994738414, 5.8651140389, 1.6124771946
), RNATURALINC2016 = c(3.912431139, 2.6351400388, 3.123605796,
3.969532736, 5.4640183742, 1.5900546466), RNATURALINC2017 =
c(3.4634804902,
2.0606169731, 2.8735476848, 3.4715095687, 4.9943340813, 1.0731154898
), RNATURALINC2018 = c(3.1932048488, 1.8260576141, 2.687887693,
3.1462232219, 4.6998187519, 0.7766062675), RINTERNATIONALMIG2011 =
c(2.5539481982,
3.7247036946, 1.7438348531, 2.4715029092, 2.5385138982, 0.9841112772
), RINTERNATIONALMIG2012 = c(2.7460490726, 3.7275831375, 1.7993217139,
2.9505576333, 2.5429438207, 1.2219173785), RINTERNATIONALMIG2013 =
c(2.7017267715,
3.4759149144, 1.8781318506, 2.7997195452, 2.7121923767, 1.0597112344
), RINTERNATIONALMIG2014 = c(2.988275652, 3.9792291689, 1.9851256285,
3.0689308523, 3.0260314993, 0.7759790947), RINTERNATIONALMIG2015 =
c(3.3285982753,
4.0561842059, 2.1052580818, 3.5654043717, 3.5102060089, 0.9664136698
), RINTERNATIONALMIG2016 = c(3.3215493142, 4.2230961065, 2.1323795548,
3.5885415898, 3.2920380658, 1.2245437674), RINTERNATIONALMIG2017 =
c(2.9410856198,
3.8503376372, 1.8510505744, 3.2892897676, 2.6864164429, 0.6550398799
), RINTERNATIONALMIG2018 = c(3.0010858795, 4.0950670621, 1.8698304564,
3.3695510667, 2.6156748143, 0.685035969), RDOMESTICMIG2011 = c(0,
-2.879569389, -2.786843372, 2.9081645678, 0.1508443529, -0.467223314
), RDOMESTICMIG2012 = c(0, -3.686820778, -2.69589683, 2.8855541222,
0.6834160664, 0.0122732593), RDOMESTICMIG2013 = c(0, -3.872925953,
-1.835626629, 2.4903472978, 0.6316815776, 0.5475831286), RDOMESTICMIG2014
= c(0,
-4.903180146, -2.700781819, 3.1374707924, 1.1220952977, -0.156105573
), RDOMESTICMIG2015 = c(0, -6.067919504, -3.462920156, 3.7630900106,
1.6177886489, -0.320350145), RDOMESTICMIG2016 = c(0, -6.653555548,
-3.359190761, 3.6365043774, 2.0802759896, -0.40687782), RDOMESTICMIG2017 =
c(0,
-5.651919379, -2.370672066, 2.963134779, 1.4785645494, 0.4240305179
), RDOMESTICMIG2018 = c(0, -5.222289092, -2.301663494, 2.7793734944,
1.350093835, 1.1713623417), RNETMIG2011 = c(2.5539481982, 0.845134306,
-1.043008519, 5.379667477, 2.6893582511, 0.516887963), RNETMIG2012 =
c(2.7460490726,
0.0407623599, -0.896575116, 5.8361117555, 3.2263598871, 1.2341906378
), RNETMIG2013 = c(2.7017267715, -0.397011039, 0.0425052219,
5.2900668429, 3.3438739543, 1.6072943629), RNETMIG2014 = c(2.988275652,
-0.923950977, -0.71565619, 6.2064016447, 4.148126797, 0.6198735214
), RNETMIG2015 = c(3.3285982753, -2.011735298, -1.357662074,
7.3284943823, 5.1279946578, 0.6460635248), RNETMIG2016 = c(3.3215493142,
-2.430459441, -1.226811206, 7.2250459672, 5.3723140554, 0.8176659475
), RNETMIG2017 = c(2.9410856198, -1.801581742, -0.519621492,
6.2524245465, 4.1649809923, 1.0790703978), RNETMIG2018 = c(3.0010858795,
-1.12722203, -0.431833037, 6.1489245611, 3.9657686492, 1.8563983107
)), .Names = c("SUMLEV", "REGION", "DIVISION", "STATE", "NAME",
"CENSUS2010POP", "ESTIMATESBASE2010", "POPESTIMATE2010",
"POPESTIMATE2011",
"POPESTIMATE2012", "POPESTIMATE2013", "POPESTIMATE2014",
"POPESTIMATE2015",
"POPESTIMATE2016", "POPESTIMATE2017", "POPESTIMATE2018", "NPOPCHG_2010",
"NPOPCHG_2011", "NPOPCHG_2012", "NPOPCHG_2013", "NPOPCHG_2014",
"NPOPCHG_2015", "NPOPCHG_2016", "NPOPCHG_2017", "NPOPCHG_2018",
"BIRTHS2010", "BIRTHS2011", "BIRTHS2012", "BIRTHS2013", "BIRTHS2014",
"BIRTHS2015", "BIRTHS2016", "BIRTHS2017", "BIRTHS2018", "DEATHS2010",
"DEATHS2011", "DEATHS2012", "DEATHS2013", "DEATHS2014", "DEATHS2015",
"DEATHS2016", "DEATHS2017", "DEATHS2018", "NATURALINC2010",
"NATURALINC2011",
"NATURALINC2012", "NATURALINC2013", "NATURALINC2014", "NATURALINC2015",
"NATURALINC2016", "NATURALINC2017", "NATURALINC2018",
"INTERNATIONALMIG2010",
"INTERNATIONALMIG2011", "INTERNATIONALMIG2012", "INTERNATIONALMIG2013",
"INTERNATIONALMIG2014", "INTERNATIONALMIG2015", "INTERNATIONALMIG2016",
"INTERNATIONALMIG2017", "INTERNATIONALMIG2018", "DOMESTICMIG2010",
"DOMESTICMIG2011", "DOMESTICMIG2012", "DOMESTICMIG2013",
"DOMESTICMIG2014",
"DOMESTICMIG2015", "DOMESTICMIG2016", "DOMESTICMIG2017",
"DOMESTICMIG2018",
"NETMIG2010", "NETMIG2011", "NETMIG2012", "NETMIG2013", "NETMIG2014",
"NETMIG2015", "NETMIG2016", "NETMIG2017", "NETMIG2018", "RESIDUAL2010",
"RESIDUAL2011", "RESIDUAL2012", "RESIDUAL2013", "RESIDUAL2014",
"RESIDUAL2015", "RESIDUAL2016", "RESIDUAL2017", "RESIDUAL2018",
"RBIRTH2011", "RBIRTH2012", "RBIRTH2013", "RBIRTH2014", "RBIRTH2015",
"RBIRTH2016", "RBIRTH2017", "RBIRTH2018", "RDEATH2011", "RDEATH2012",
"RDEATH2013", "RDEATH2014", "RDEATH2015", "RDEATH2016", "RDEATH2017",
"RDEATH2018", "RNATURALINC2011", "RNATURALINC2012", "RNATURALINC2013",
"RNATURALINC2014", "RNATURALINC2015", "RNATURALINC2016",
"RNATURALINC2017",
"RNATURALINC2018", "RINTERNATIONALMIG2011", "RINTERNATIONALMIG2012",
"RINTERNATIONALMIG2013", "RINTERNATIONALMIG2014", "RINTERNATIONALMIG2015",
"RINTERNATIONALMIG2016", "RINTERNATIONALMIG2017", "RINTERNATIONALMIG2018",
"RDOMESTICMIG2011", "RDOMESTICMIG2012", "RDOMESTICMIG2013",
"RDOMESTICMIG2014",
"RDOMESTICMIG2015", "RDOMESTICMIG2016", "RDOMESTICMIG2017",
"RDOMESTICMIG2018",
"RNETMIG2011", "RNETMIG2012", "RNETMIG2013", "RNETMIG2014", "RNETMIG2015",
"RNETMIG2016", "RNETMIG2017", "RNETMIG2018"), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
In order to help you out, an example data using dput(head(population.data)) would be helpful. Based on your comments, your data is in what is called 'wide' format, meaning each observation is contained in a column, rather than a row (pupulation 2010, population 2011 etc.).
As i hinted in my comment, a sub-goal within statistical modelling is always to clean and reshape data to a proper format, that will work for running models. In this case the problem is that your format is in an incorrect shape. The most common is likely melting to long format via the reshape2 or data.table package as explained in this link. I personally prefer the data.table package, as it seems to have better large scale performance. Their usage however is identical.
Lets say you have a column 'NAME' for states and 9 columns for population estimates (2010 population estimates, 2011 population estimates and so on), we could then convert these columns into a long format, using melt from either of the two suggested packages (They are identical in use)
require(data.table)
value_columns <- paste(2010:2018, "Population Estimates")
population.data_long <- melt(population.data, id.vars = "NAME",
measure.vars = value_columns, #Columns containing values we (that are grouped by their column names)
variable.name = 'Year (Population Estimate)', #Name of the column which tells us [(Year) Population Estimate]
value.name = 'Population Estimate') #Name of the column with values
population.data_long$year <- as.integer(substr(population.data_long$`Year (Population Estimate)`, 1, 4)) #Create a year column in a bit of a hacky way
Note i have ignored any additional columns, and these should be included in your melt statement. From here on a linear regression should follow any standard example that you have found.

gganimate zoom in on data while keeping map as background doesnt work

I am trying to plot a path of gps points I have (the included example is a of a train ride in the Netherlands). I would like to make use of the
shadow_mark() and view_follow() functions of the gganimate() package, such that the plot starts fully zoomed in and then progressingly zooms out. This works fine if I do not use either google or OSM map as a background, but I would like to use one of these (not picky). I have tried to play around with
the exclude_layer = command, but cannot seem to get it to work. If I use a map as background the animation is zoomed out from the 1st frame.
I looked around the vignettes, but could not find an example of view_follow() being used together with a map as background.
Set up packages and data (200 gps points)
require(gganimate)
require(tidyverse)
require(lubridate)
require(ggmap)
library(OpenStreetMap)
df3 <- structure(list(lat = c(52.0473442, 52.0173027, 52.0898208, 52.0309643,
52.0497488, 52.0897325, 52.0892640857143, 52.0179681, 52.0383389,
52.1048323, 52.0181769, 52.0289188, 52.0941033, 52.0182591, 52.0882347,
52.090628, 52.1060504, 52.0893178, 52.1062902, 52.015563475,
52.1041445, 52.09096297, 52.0095689, 52.0460849, 52.0949215,
52.0243182, 52.066435, 52.0273662, 52.1055631, 52.0893175, 52.0487954,
52.0980435, 52.09089341, 52.0145649, 52.0089167, 52.0605713,
52.009809, 52.0895006516129, 52.0893323, 52.0959561, 52.0659477,
52.0514133, 52.08956736, 52.0898078, 52.0971748, 52.0131978,
52.049002, 52.0182712, 52.1045885, 52.0895501, 52.062702, 52.0919686,
52.0163620216216, 52.09101514, 52.0895122571429, 52.0906238,
52.1049253, 52.0085885, 52.0948177, 52.0906366, 52.0894994903226,
52.103213, 52.0372776, 52.0468101, 52.0485351, 52.0874545, 52.0392919,
52.0892646285714, 52.08922625, 52.0143929, 52.0503487, 52.0598063,
52.0894236363636, 52.0895004193548, 52.0895104285714, 52.08926629,
52.0204065, 52.0494409, 52.0894992580645, 52.0149126096774, 52.0910172,
52.0163522, 52.1038697666667, 52.0175865, 52.1011104, 52.1022396,
52.0508854, 52.0326581, 52.0893379636364, 52.0936814, 52.0608923,
52.0171837, 52.0207873, 52.0892670714286, 52.089319, 52.1019613,
52.1005872, 52.0430951, 52.0898355, 52.0893309181818, 52.0180603,
52.0390661, 52.0348046, 52.0481463, 52.0420622, 52.0167229, 52.0523997,
52.0172069, 52.0412617, 52.0212251, 52.0894450545455, 52.0381603,
52.0988658, 52.0892341636364, 52.0167707108108, 52.0856953, 52.0455796,
52.0893241, 52.0974118, 52.10305028, 52.0975816, 52.0906235,
52.100775, 52.0748232, 52.0102848, 52.089504, 52.0164101027027,
52.0083622, 52.0895125619048, 52.038528, 52.1041174, 52.0963176,
52.0153379, 52.1024123, 52.0895413, 52.0931169, 52.015444875,
52.0386511, 52.0516474, 52.0895002451613, 52.0215369, 52.0991255,
52.0969218, 52.0893316, 52.066435, 52.0139796, 52.0981765, 52.0897099,
52.0352992, 52.051733, 52.0530949, 52.08922647, 52.0107568, 52.0677648,
52.0895214666667, 52.089504648, 52.100359, 52.09324255, 52.0620195,
52.0466879, 52.017858, 52.0135695, 52.0254736, 52.0171776, 52.028283,
52.0171794, 52.1010769, 52.0178973, 52.0924092, 52.0897434, 52.0505729,
52.0291358, 52.0893442, 52.0086011, 52.0992469, 52.059978, 52.0897928,
52.0892269041667, 52.1054074, 52.089251, 52.0526539, 52.0266356,
52.0449901, 52.1051109, 52.0612085, 52.0897635, 52.0618627, 52.0894992,
52.1059497, 52.015919275, 52.0114324, 52.0511659, 52.0892549333333,
52.0235488, 52.0272761, 52.09694, 52.0521608, 52.0153993, 52.1060753,
52.0175162), lon = c(4.8527414, 4.7043579, 5.1092251, 4.558967,
4.4474887, 5.1093993, 5.10904667619048, 4.7878027, 4.8367076,
4.95351535, 4.6931897, 4.567024, 5.105847, 4.6899796, 4.9029363,
5.1110543, 4.96241255, 5.108432375, 4.9690878, 4.73307101555556,
4.9939, 5.110891905, 4.6441234, 4.496551, 5.1049426, 4.5854403,
4.3598875, 4.8104103, 4.9753691, 5.10843242142857, 4.4603587,
4.9321842, 5.110488365, 4.624286, 4.6469115, 4.865213, 4.6431315,
5.1097292516129, 5.10848633, 4.9263356, 4.3614653, 4.4245138,
5.10908557, 5.1092372, 4.929797, 4.6298071, 4.8542748, 4.691945,
4.9882762, 4.9068603, 4.3707472, 5.1076963, 4.71963735765766,
5.11119456, 5.10973931428571, 5.1110549, 4.9540848, 4.6488539,
5.1050478, 5.1110486, 5.10973009032258, 5.0053341, 4.8341014,
4.4882284, 4.4640663, 4.9004724, 4.8388151, 5.10903851428571,
5.10884365, 4.7520508, 4.4393094, 4.8644185, 5.10953031818182,
5.10972941935484, 5.10973205714286, 5.10849255, 4.601082, 4.4515908,
5.10973025806452, 4.74402028494624, 5.1111849, 4.676354, 4.99798836666667,
4.7009575, 5.031704, 5.0167332, 4.4321563, 4.8230864, 5.10928108181818,
5.1062712, 4.3758328, 4.7058636, 4.5995564, 5.10900178571429,
5.10843218928571, 5.0200993, 5.0389258, 4.8472408, 5.1091899,
5.10847912727273, 4.6946867, 4.5265032, 4.8282194, 4.4697327,
4.5144658, 4.6157094, 4.4114789, 4.6803854, 4.8436428, 4.5977714,
5.10959262727273, 4.8362508, 5.0669724, 5.10884347272727, 4.71276212882883,
4.8951137, 4.5001568, 5.1084314, 5.0888354, 5.0070498, 5.0845948,
5.1110552, 5.0356131, 4.878915, 4.6636436, 5.10892755, 4.71882850720721,
4.65157, 5.10974052380952, 4.8371255, 4.9957208, 5.1016242, 4.673318,
5.0145183, 5.1100309, 5.1067818, 4.73506618, 4.5281429, 4.4214528,
5.10972954516129, 4.7963679, 5.0638705, 5.0952241, 5.1084839,
4.3598875, 4.7581467, 5.0759648, 5.1094376, 4.829447, 4.4204181,
4.4020959, 5.10884371, 4.6393904, 4.3563094, 5.109842, 5.109726984,
5.0417278, 4.91819815, 4.3726141, 4.4892613, 4.6975655, 4.6697432,
4.580841, 4.7058672, 4.8126885, 4.7058869, 4.9413298, 4.6971556,
4.9156515, 5.109391, 4.4370594, 4.5661368, 5.10852764, 4.6569508,
5.0618936, 4.3785312, 5.1092584, 5.108826925, 4.9785586, 5.10890992857143,
4.8577536, 4.5762531, 4.5027296, 4.9817912, 4.3749189, 5.1093724,
4.373075, 5.1097303, 4.9606803, 4.72708552222222, 4.6660585,
4.4280254, 5.1089249, 4.5886027, 4.5736119, 5.0948948, 4.4141114,
4.7804527, 4.97133625, 4.6823925), time = structure(c(1549542028,
1549541565, 1549542658, 1549541192, 1549540912, 1549542689, 1549542880,
1549541872, 1549541986, 1549542287, 1549541524, 1549541210, 1549542600,
1549541514, 1549542184, 1549543182, 1549542303, 1549543013, 1549542315,
1549541756, 1549542360, 1549543125, 1549541393, 1549541039, 1549542592,
1549541253, 1549540695, 1549541925, 1549542326, 1549543012, 1549540937,
1549542243, 1549543129, 1549541352, 1549541399, 1549542075, 1549541391,
1549542809, 1549543046, 1549542231, 1549540734, 1549540867, 1549543079,
1549542660, 1549542238, 1549541363, 1549542034, 1549541520, 1549542350,
1549542192, 1549540756, 1549542623, 1549541704, 1549543122, 1549542766,
1549543211, 1549542288, 1549541403, 1549542593, 1549543174, 1549542829,
1549542381, 1549541980, 1549541009, 1549540944, 1549542179, 1549541991,
1549542882, 1549542947, 1549541800, 1549540896, 1549542072, 1549542861,
1549542813, 1549542772, 1549543000, 1549541296, 1549540920, 1549542833,
1549541784, 1549543143, 1549541474, 1549542368, 1549541550, 1549542428,
1549542401, 1549540882, 1549541954, 1549542869, 1549542604, 1549540767,
1549541600, 1549541292, 1549542891, 1549543017, 1549542407, 1549542441,
1549542011, 1549542653, 1549543044, 1549541529, 1549541119, 1549541966,
1549540955, 1549541091, 1549541333, 1549540842, 1549541485, 1549542002,
1549541287, 1549542859, 1549541985, 1549542493, 1549542970, 1549541687,
1549542168, 1549541052, 1549543034, 1549542539, 1549542384, 1549542529,
1549543225, 1549542435, 1549542125, 1549541436, 1549543075, 1549541702,
1549541409, 1549542765, 1549541987, 1549542364, 1549542577, 1549541466,
1549542397, 1549542736, 1549542610, 1549541764, 1549541123, 1549540861,
1549542816, 1549541892, 1549542487, 1549542555, 1549543045, 1549540730,
1549541812, 1549542511, 1549542701, 1549541969, 1549540859, 1549540824,
1549542949, 1549541383, 1549540720, 1549542756, 1549542791, 1549542446,
1549542215, 1549540760, 1549541013, 1549541538, 1549541455, 1549541242,
1549541668, 1549541930, 1549541670, 1549542262, 1549541537, 1549542210,
1549542688, 1549540892, 1549541208, 1549543063, 1549541420, 1549542483,
1549540773, 1549542679, 1549542925, 1549542332, 1549542906, 1549542047,
1549541231, 1549541060, 1549542338, 1549540765, 1549542686, 1549540761,
1549542834, 1549542300, 1549541732, 1549541443, 1549540874, 1549542904,
1549541261, 1549541225, 1549542554, 1549540847, 1549541856, 1549542319,
1549541491), class = c("POSIXct", "POSIXt"), tzone = "Europe/Paris")), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -200L), .Names = c("lat",
"lon", "time"))
load maps as background
LAT1 = in(df3$lat) -.07
LAT2 = max(df3$lat) +.07
LON1 = min(df3$lon) -.07
LON2 = max(df3$lon) +.07
map_osm <- openmap(c(LAT2,LON1), c(LAT1,LON2), zoom = NULL,
type = "stamen-toner",
mergeTiles = TRUE,
minNumTiles=10)
map_osm <- openproj(map_osm, projection = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
map_google_box <- make_bbox(lat = df3$lat, lon = df3$lon, f = 0.5)
map_google <- get_map(location = map_google_box)
animations
# this works
ani1 <- ggplot()+
geom_point(data = df3,
aes(y =lat, x= lon),
size = 2,
col = 'red')+
transition_time(time) +
ease_aes('linear')+
shadow_mark()+
view_follow()
animate(ani1)
# this doesnt
ani2 <- ggmap(map_google) +
geom_point(data = df3,
aes(y =lat, x= lon),
size = 2,
col = 'red')+
transition_time(time) +
ease_aes('linear')+
shadow_mark()+
view_follow()
animate(ani2)
# this doesnt either
ani3 <- autoplot(map_osm) +
geom_point(data = df3,
aes(y =lat, x= lon),
size = 2,
col = 'red')+
transition_time(time) +
ease_aes('linear')+
shadow_mark()+
view_follow()
animate(ani3)

Plotting `ggplot` sorted on specific value

I have the below results and I am trying to plot using ggplot the columns using the code below but ordered such that the first ranked plot on the legend will correspond to the highest score (taken from the last row in the data). So for example the plots would be ordered in the following way, which on the legend will look like;
train_auc_9 (result = 0.9939489)
train_auc_6 (result = 0.9870544)
train_auc_3 (result = 0.9699427)
train_auc_8 (result = 0.9662169)
train_auc_7 (result = 0.9662169) etc.
Should I sort the columns based on final row value first to make life easier?
ggplot code:
ggplot(result_train_auc, aes(ID)) +
geom_line(aes(y = train_auc_1, colour = "train_auc_1")) +
geom_line(aes(y = train_auc_2, colour = "train_auc_2")) +
geom_line(aes(y = train_auc_3, colour = "train_auc_3")) +
geom_line(aes(y = train_auc_4, colour = "train_auc_4")) +
geom_line(aes(y = train_auc_5, colour = "train_auc_5")) +
geom_line(aes(y = train_auc_6, colour = "train_auc_5")) +
geom_line(aes(y = train_auc_7, colour = "train_auc_6")) +
geom_line(aes(y = train_auc_8, colour = "train_auc_7")) +
geom_line(aes(y = train_auc_8, colour = "train_auc_8")) +
geom_line(aes(y = train_auc_8, colour = "train_auc_9"))
ggtitle("auc curves") +
labs(y="auc result", x = "rounds") +
theme_bw(base_size = 11, base_family = "")
Final row of the data.
0.9177697
0.9309705
0.9699427
0.9431463
0.9544374
0.9870544
0.9538312
0.9662169
0.9939489
100
data called result_train_auc.
structure(list(train_auc_1 = c(0.8713344, 0.8871179, 0.8928057,
0.8964518, 0.8976864, 0.8995532, 0.9001708, 0.9015733, 0.9022265,
0.9027288, 0.9031676, 0.9036361, 0.9040329, 0.9045184, 0.9048802,
0.9053402, 0.9055032, 0.9056735, 0.9061118, 0.9062926, 0.9064719,
0.9067036, 0.9069563, 0.9071833, 0.9074455, 0.907724, 0.907817,
0.9081296, 0.9082689, 0.9084679, 0.9086163, 0.9087718, 0.9091238,
0.9093731, 0.9095402, 0.909702, 0.909771, 0.9099373, 0.9101334,
0.9103078, 0.9104885, 0.9106456, 0.9107819, 0.9108925, 0.9111391,
0.9112471, 0.9114579, 0.9115598, 0.9116752, 0.9117411, 0.9118367,
0.9120177, 0.9121465, 0.9123075, 0.9125142, 0.9125989, 0.9127896,
0.9128665, 0.9129764, 0.9130837, 0.9132152, 0.9133399, 0.9135001,
0.9136408, 0.9137385, 0.9138751, 0.9139981, 0.9140897, 0.914189,
0.9142859, 0.9144037, 0.9145455, 0.9146629, 0.9147381, 0.9148613,
0.9149902, 0.9150876, 0.9151985, 0.9153009, 0.9154068, 0.915529,
0.9156637, 0.9157626, 0.9158646, 0.915995, 0.9161135, 0.9162173,
0.9163324, 0.91642, 0.9165297, 0.9166981, 0.9168092, 0.9169468,
0.9170768, 0.9171896, 0.9173152, 0.9174244, 0.9175383, 0.9176803,
0.9177697), train_auc_2 = c(0.8870459, 0.9021414, 0.9085472,
0.9114717, 0.9136837, 0.9148831, 0.9160633, 0.916577, 0.9175609,
0.918181, 0.9185195, 0.9189418, 0.919285, 0.9195346, 0.9197795,
0.9201756, 0.9205287, 0.9207205, 0.9208646, 0.9210185, 0.9211867,
0.9213273, 0.9214634, 0.9217073, 0.921851, 0.9220127, 0.9221905,
0.9224531, 0.9227193, 0.9228104, 0.9229566, 0.9231306, 0.9233425,
0.9234565, 0.9235739, 0.9237399, 0.9239113, 0.9240052, 0.9242447,
0.9243938, 0.9245815, 0.9247349, 0.92491, 0.9250047, 0.9251303,
0.9252628, 0.925474, 0.9256335, 0.9257628, 0.9258756, 0.9259525,
0.9260501, 0.9261603, 0.9262516, 0.926404, 0.9264811, 0.9266122,
0.9267074, 0.9268346, 0.9269162, 0.9270102, 0.9271369, 0.9272119,
0.9273092, 0.9274163, 0.9275176, 0.9276396, 0.9277829, 0.9278664,
0.927978, 0.928066, 0.9281753, 0.9283186, 0.928417, 0.9285194,
0.9286077, 0.9286985, 0.9287818, 0.9288713, 0.9289982, 0.9290624,
0.9291517, 0.929267, 0.9293397, 0.9294468, 0.9295616, 0.9296748,
0.9297741, 0.9298962, 0.929982, 0.9300875, 0.9301889, 0.9302799,
0.9303726, 0.9304612, 0.930582, 0.9306869, 0.9307636, 0.9308679,
0.9309705), train_auc_3 = c(0.920364, 0.9396713, 0.9477804, 0.9511932,
0.9533659, 0.9548309, 0.9560987, 0.9569889, 0.9577224, 0.9580906,
0.9585115, 0.9590348, 0.9592664, 0.9596969, 0.9600961, 0.9603775,
0.9605959, 0.9608837, 0.9611088, 0.9612673, 0.9614595, 0.9616898,
0.9618144, 0.961986, 0.9621864, 0.9623498, 0.9624878, 0.9626525,
0.9627835, 0.9628886, 0.9629866, 0.9631557, 0.9632875, 0.9634212,
0.9635417, 0.9636695, 0.9637814, 0.9638905, 0.9639689, 0.9640757,
0.964196, 0.9643034, 0.9644215, 0.9645278, 0.9646416, 0.9647334,
0.9648655, 0.9649719, 0.9650779, 0.9651884, 0.9653068, 0.9654192,
0.9655179, 0.9656188, 0.9657627, 0.965861, 0.9659789, 0.966077,
0.9661733, 0.966301, 0.9664198, 0.9664838, 0.9665656, 0.9666834,
0.9667807, 0.9668807, 0.9669509, 0.9670521, 0.9671343, 0.9672346,
0.967336, 0.9674322, 0.9675225, 0.9676096, 0.9677119, 0.9678031,
0.967893, 0.9679848, 0.9680899, 0.968179, 0.9682643, 0.9683379,
0.9684383, 0.9685187, 0.9686161, 0.9687164, 0.9688037, 0.9688999,
0.9689951, 0.9690893, 0.9691872, 0.9692667, 0.9693624, 0.9694321,
0.9695126, 0.9695981, 0.9696739, 0.9697611, 0.9698583, 0.9699427
), train_auc_4 = c(0.8719551, 0.8896184, 0.8948779, 0.898766,
0.9027315, 0.9049762, 0.9062427, 0.9073199, 0.9081683, 0.9092019,
0.9100824, 0.9109981, 0.9116318, 0.9123474, 0.9131612, 0.9138763,
0.9145007, 0.9152897, 0.9158685, 0.9166697, 0.9172174, 0.9179825,
0.9186526, 0.9193314, 0.9199804, 0.9205763, 0.9212371, 0.921792,
0.9223935, 0.9229936, 0.9234932, 0.9240162, 0.9245426, 0.9250783,
0.9256483, 0.9262044, 0.9267231, 0.9271653, 0.9276435, 0.9280976,
0.9284953, 0.9289266, 0.9293313, 0.9297668, 0.9301079, 0.9305796,
0.9309791, 0.9314001, 0.9317514, 0.932084, 0.9323953, 0.9326925,
0.9330121, 0.933329, 0.9335974, 0.9339083, 0.934189, 0.9344819,
0.934775, 0.9350779, 0.9353696, 0.9356319, 0.9358907, 0.9361598,
0.9364136, 0.936647, 0.9368967, 0.9370801, 0.9373547, 0.9375985,
0.9378257, 0.9380637, 0.9382862, 0.9385131, 0.9387194, 0.9389419,
0.9391624, 0.9393709, 0.939553, 0.9397668, 0.9399806, 0.9401861,
0.9403382, 0.9404968, 0.9406843, 0.9408617, 0.9410371, 0.9412126,
0.9413865, 0.9415654, 0.9417246, 0.9418873, 0.9420531, 0.9422337,
0.9423998, 0.9425335, 0.9426956, 0.9428642, 0.9429921, 0.9431463
), train_auc_5 = c(0.8894875, 0.9047447, 0.9105668, 0.9144695,
0.9172043, 0.9185459, 0.919896, 0.9209646, 0.9220889, 0.9229307,
0.923797, 0.9245408, 0.9252745, 0.9258488, 0.9264725, 0.9270811,
0.927705, 0.9283463, 0.9288456, 0.9293815, 0.9299636, 0.9305526,
0.9311112, 0.9317484, 0.9323305, 0.9328307, 0.9332667, 0.9338263,
0.9343498, 0.9348398, 0.9353667, 0.9358599, 0.9362733, 0.9367398,
0.9371676, 0.9376035, 0.9380137, 0.93843, 0.9388201, 0.9392386,
0.9396649, 0.9400335, 0.940358, 0.940702, 0.9410648, 0.9414072,
0.9417623, 0.9421251, 0.9424502, 0.9428179, 0.9431571, 0.9434742,
0.9438279, 0.9441624, 0.9444683, 0.944784, 0.9450568, 0.9453451,
0.9456379, 0.9459065, 0.9462062, 0.9464493, 0.9467355, 0.9469841,
0.9472465, 0.9475116, 0.9477762, 0.948027, 0.9482639, 0.9485123,
0.9487707, 0.9489929, 0.9492213, 0.9494459, 0.9497089, 0.9499556,
0.9501546, 0.9503753, 0.9505703, 0.9507616, 0.9509694, 0.9511743,
0.9513489, 0.9515396, 0.9517049, 0.9518854, 0.9520863, 0.9522618,
0.9524513, 0.9526601, 0.9528238, 0.9530262, 0.953238, 0.9534353,
0.9535989, 0.9537715, 0.953945, 0.9541034, 0.9542643, 0.9544374
), train_auc_6 = c(0.921898, 0.9414678, 0.9480329, 0.9519876,
0.9548386, 0.9567495, 0.9580347, 0.959306, 0.9603841, 0.9614684,
0.9623793, 0.9630147, 0.9637751, 0.964326, 0.9648042, 0.9653413,
0.9658432, 0.9664368, 0.9670508, 0.9675288, 0.9681021, 0.9685874,
0.969052, 0.9695682, 0.9699854, 0.9704805, 0.9708863, 0.97131,
0.9717166, 0.9721004, 0.9724803, 0.9728962, 0.9732809, 0.9736517,
0.9740503, 0.9744405, 0.974781, 0.9751438, 0.9754958, 0.9758019,
0.9761391, 0.9764902, 0.9768141, 0.9771417, 0.9774458, 0.9777964,
0.9780874, 0.9783719, 0.9786893, 0.9789502, 0.9792233, 0.9794795,
0.979716, 0.9799766, 0.9802053, 0.9804437, 0.9806533, 0.9808698,
0.9810933, 0.9813374, 0.9815627, 0.9817506, 0.9819429, 0.9821263,
0.9823146, 0.9824981, 0.9826867, 0.9828871, 0.9830589, 0.9832092,
0.9833926, 0.983539, 0.983694, 0.9838324, 0.9839557, 0.9841259,
0.9843032, 0.9844521, 0.9845934, 0.9847127, 0.9848563, 0.9849894,
0.9851023, 0.9852643, 0.9853757, 0.9854869, 0.9856046, 0.9857333,
0.9858394, 0.9859424, 0.9860531, 0.9861587, 0.986294, 0.9864175,
0.9865295, 0.9866261, 0.9867294, 0.986843, 0.9869372, 0.9870544
), train_auc_7 = c(0.8714998, 0.8904612, 0.8996561, 0.9041253,
0.9066398, 0.9086743, 0.910345, 0.9116165, 0.9130665, 0.914957,
0.9166201, 0.9180005, 0.9195517, 0.9207296, 0.9218763, 0.9230211,
0.9241087, 0.9252396, 0.9262592, 0.9271692, 0.9280938, 0.9289803,
0.9297884, 0.9305648, 0.9311738, 0.9317921, 0.9323804, 0.9329845,
0.933683, 0.9341942, 0.9347607, 0.9352553, 0.9357764, 0.9363214,
0.9367976, 0.9372965, 0.9377839, 0.9382045, 0.9386436, 0.9391153,
0.939509, 0.9399301, 0.9402878, 0.9405964, 0.9409411, 0.9413296,
0.9416693, 0.9419742, 0.9423106, 0.9426316, 0.9428824, 0.94322,
0.9435017, 0.9438152, 0.9440885, 0.9443691, 0.9446256, 0.9449214,
0.9451091, 0.945326, 0.9456083, 0.9458252, 0.9460603, 0.94633,
0.946581, 0.9468279, 0.9470671, 0.9473089, 0.9474984, 0.9477469,
0.9479721, 0.9482038, 0.9484291, 0.9486507, 0.9488756, 0.9490827,
0.9492949, 0.9494745, 0.9497085, 0.9499118, 0.9501382, 0.9503468,
0.9505637, 0.9507583, 0.9509843, 0.9512342, 0.9514627, 0.9516457,
0.9518377, 0.9520731, 0.9522473, 0.9524432, 0.9526339, 0.9528058,
0.9529749, 0.9531575, 0.9533158, 0.953497, 0.953663, 0.9538312
), train_auc_8 = c(0.8894918, 0.906573, 0.9133049, 0.9168864,
0.9194233, 0.9219299, 0.9237789, 0.9252068, 0.9265656, 0.9281103,
0.929274, 0.9307909, 0.9317895, 0.9328411, 0.933978, 0.9349498,
0.9358906, 0.936782, 0.9376891, 0.9385461, 0.9393091, 0.9401118,
0.940883, 0.941568, 0.9421953, 0.9427495, 0.9434112, 0.9439894,
0.944666, 0.9452999, 0.9457854, 0.9463698, 0.9468706, 0.9473643,
0.947829, 0.9482811, 0.9487576, 0.9492046, 0.9496415, 0.9500149,
0.9504884, 0.9509045, 0.9512969, 0.951719, 0.95214, 0.9525265,
0.9528557, 0.9531854, 0.9535102, 0.9537721, 0.9541137, 0.9544496,
0.9548184, 0.9551027, 0.955434, 0.9557073, 0.955989, 0.9563086,
0.9565974, 0.9569073, 0.9571664, 0.9574366, 0.9577329, 0.9580357,
0.9582985, 0.9585633, 0.9587903, 0.9590735, 0.9593316, 0.9596137,
0.9598677, 0.9600993, 0.9602947, 0.9605253, 0.9607954, 0.9610258,
0.9612257, 0.9614929, 0.9617122, 0.9619397, 0.9622056, 0.9624263,
0.9626628, 0.9628691, 0.9631282, 0.9633603, 0.9635655, 0.9638023,
0.9640161, 0.9642836, 0.9644966, 0.9646435, 0.9648045, 0.964987,
0.9652297, 0.9654192, 0.9655976, 0.9657743, 0.965976, 0.9662169
), train_auc_9 = c(0.9195993, 0.9417172, 0.949147, 0.9537538,
0.9565765, 0.9589093, 0.9607099, 0.962332, 0.9639256, 0.9652906,
0.9664848, 0.9675891, 0.9685598, 0.9695702, 0.9705377, 0.9713772,
0.9722889, 0.9730441, 0.9738743, 0.9745701, 0.9752537, 0.9759395,
0.9765657, 0.9772191, 0.9778215, 0.9783909, 0.9789667, 0.979504,
0.9799884, 0.9804533, 0.9808872, 0.9813206, 0.981738, 0.982081,
0.9824229, 0.9827401, 0.983044, 0.9833385, 0.9836874, 0.9840525,
0.9843545, 0.9845821, 0.984868, 0.985124, 0.9853725, 0.9855741,
0.9857704, 0.9860043, 0.986215, 0.9864325, 0.9865974, 0.9867876,
0.9870471, 0.9872346, 0.987455, 0.9877028, 0.9879157, 0.9880718,
0.9882622, 0.9884967, 0.9886666, 0.9888404, 0.9890087, 0.9891979,
0.9893628, 0.9895276, 0.9896856, 0.989821, 0.9899959, 0.9901792,
0.9903423, 0.9905105, 0.9906635, 0.9908151, 0.99095, 0.991091,
0.9912231, 0.9913755, 0.9914875, 0.9916226, 0.991765, 0.9919017,
0.9920161, 0.9921698, 0.9923023, 0.9924097, 0.9925314, 0.9926483,
0.9927896, 0.992922, 0.9930381, 0.9931279, 0.9932223, 0.9933255,
0.9934563, 0.99354, 0.9936327, 0.9937486, 0.9938403, 0.9939489
), ID = 1:100), .Names = c("train_auc_1", "train_auc_2", "train_auc_3",
"train_auc_4", "train_auc_5", "train_auc_6", "train_auc_7", "train_auc_8",
"train_auc_9", "ID"), row.names = c(NA, -100L), class = "data.frame")
EDIT: Added a picture for clarification.
Here is a way to do it. Notice that I reshape the data to use full power of plotting aesthetics:
library(tidyr)
library(ggplot2)
# reshape the data
df %>%
gather(trainauc, value, -ID) -> df
# get the order
df %>%
filter(ID == 100) %>%
arrange(desc(value)) %>%
.$trainauc -> leg_order
# plot
ggplot(df, aes(ID)) +
geom_line(aes(y = value, colour = trainauc)) +
scale_colour_discrete(breaks = leg_order) +
labs(title = "auc curves", y = "auc result", x = "rounds") +
theme_bw(base_size = 11, base_family = "") +

Plotting Curves from Data Frame Columns

i am facing a problem in plot ols estimations in a scatterplot:
I have this data frame: With 9 columns and 99 rows:
structure(list(Y = c(-0.145442175, 0.291096141, 0.489923112,
-2.038363166, 1.180430664, 0.188114666, 0.850922634, 1.172142766,
-3.980837975, 0.285762444, 2.497040646, 0.658010994, -0.925171981,
0.37076995, -1.108211119, -0.409242669, -1.234583525, -0.385841816,
0.016744771, -0.584406288, 1.17224811, -0.746804388, -0.625028046,
0.257871468, -2.735845346, 2.619304857, -0.406825232, 0.323665151,
2.218951363, -0.821029648, -0.872854889, -2.663306158, -0.121976044,
0.881566376, -1.972706678, -3.855576256, 2.927421113, 1.314753531,
0.234296206, 0.828464757, -0.909318569, 0.616134903, -0.567630403,
0.624571064, -0.414112923, 0.642200314, -0.309421266, 0.195312598,
-0.519988256, 0, 0.081070175, 0.032446432, -0.534025032, -0.426783307,
-0.38495511, -0.207900219, -1.953789746, -0.616924355, -0.783222881,
-1.935420969, 0.638445535, 1.080925923, -1.598076681, 0.25063631,
-0.697183766, 0.188971653, -0.415267389, -4.154506044, 1.163226552,
0.036569698, -0.547147074, 1.11937374, 0.383311682, -0.875037781,
-0.372684863, 0.306816004, -1.250561544, -1.042237738, -1.757788446,
0.021079982, 1.844023775, 1.674645753, -0.428546132, -0.527705597,
0.542202572, -0.621479123, -0.050415867, -0.122332943, 0.468553764,
0.216998274, 3.088480781, 0.434099931, 2.114916704, -2.407018936,
-0.127060127, 0.546756422, 0.263207486, 0.63453915, 0.76832746
), X = c(0.009476137, -0.0236354, 0.0094081, 0.11715252, 0.032324021,
0.0461193, 0.050794971, 0.032372819, 0.202121874, 0.390821859,
-0.124492596, -0.127305193, -0.22233597, -0.081113713, 0.09952616,
0.22494711, 0.226621495, 0.411607624, 0.089200478, -0.013454832,
-0.013547165, -0.232366214, 0.03140992, -0.026798837, -0.084556341,
-0.091993172, -0.303730207, -0.236679148, -0.284235285, -0.355253166,
-0.179645537, -0.01381843, -0.022950244, -0.050065976, -0.032018504,
-0.087168055, -0.081865767, -0.253991077, -0.242882759, -0.150225053,
-0.16596575, -0.156887247, -0.071795146, -0.100408802, -0.067307731,
0.024006869, -0.019250912, -0.02399429, 0.038421097, 0.062320065,
0.07187025, 0.024019462, 0.038421097, 0.033539309, 0.014351457,
-0.009575137, 0.014343968, 0.028561284, 0.0404213, 0.026065697,
-0.004700435, -0.072739794, -0.042217496, -0.05889531, -0.130522139,
-0.136291869, -0.120099035, -0.091418565, -0.122040844, -0.124609029,
-0.096255449, -0.190338762, -0.11611752, -0.055598423, -0.065293448,
-0.038746326, -0.029090518, -0.067627348, -0.082097445, -0.215845836,
-0.389993696, -0.264371785, -0.126530291, -0.111840985, -0.094952196,
-0.136700196, -0.190968195, -0.156564122, -0.181077278, -0.15381292,
-0.122020692, -0.107867301, -0.068642333, -0.034348677, -0.073289926,
-0.063314884, -0.092537576, -0.165375956, -0.15042398), Null = c(-0.036795117836493,
0.0120555676565338, -0.0366906491623935, -0.22323992930528, -0.0728300398338213,
-0.0955073599141197, -0.103350601084975, -0.0729090354522075,
-0.400153521158964, -0.887015257107641, 0.1362666683468, 0.13919994231771,
0.221388292373518, 0.087380368104602, -0.189831042487278, -0.452154909992189,
-0.456044210600938, -0.948567833126862, -0.170785020294756, -0.00253939338337472,
-0.00240533038312774, 0.228145471304061, -0.0713518661553421,
0.0165138860659871, 0.0915102566139487, 0.100284493544177, 0.265652059802101,
0.230938443729295, 0.257246215885006, 0.281209408151878, 0.188533028671265,
-0.00201164134414489, 0.0110851592192505, 0.0481858583559124,
0.0237904823161768, 0.094614581053392, 0.0882862377341187, 0.241468070168396,
0.234837060900023, 0.162029971029324, 0.176601607696189, 0.168307425791361,
0.0759851164110966, 0.109970788582389, 0.0703849242291975, -0.059492586621119,
0.00581616568295407, 0.0125631925046972, -0.0827672867080164,
-0.123023227393077, -0.139691063870559, -0.0595125909296922,
-0.0827672867080164, -0.074799966578053, -0.044324863847201,
-0.00820062690976645, -0.0443132308515717, -0.0667648997869916,
-0.0860567642206439, -0.0627706942069095, -0.0153914247452083,
0.0771546773236518, 0.0377224646820258, 0.0596889425617937, 0.1425196179012,
0.148379247725525, 0.13162698340227, 0.0996137276510431, 0.133686233062275,
0.136388667637584, 0.105222539655097, 0.197385328960716, 0.127361748973716,
0.0554268640818151, 0.0678473149754353, 0.0330232883757411, 0.0197208677278167,
0.0707862239701058, 0.0885648870712001, 0.216820906265572, 0.286245951224793,
0.247258814186372, 0.138394666330137, 0.122716205945161, 0.103719679674083,
0.148789344619283, 0.197893429730301, 0.168006688568371, 0.189742414352596,
0.165430712615822, 0.133664933948451, 0.11833998959919, 0.0720581343490991,
0.0270069004188009, 0.077834296346802, 0.0653403280475977, 0.100918894574441,
0.176071877748707, 0.162219750035618), OLS_1 = c(-2.97674658085357,
-2.95792547866683, -2.97674412477729, -2.7937460366665, -2.96913739819288,
-2.95639989365184, -2.95069150171007, -2.96910314906723, -2.3856485268894,
-0.647452287114872, -2.68293610049662, -2.670570393744, -2.10297963546522,
-2.84137496711892, -2.84927190111917, -2.23638642750757, -2.22477621905134,
-0.385841816000001, -2.87715002139054, -2.96747293407547, -2.96740133507642,
-2.02609643038743, -2.9697648045679, -2.95427875550959, -2.8310157181346,
-2.80733412921436, -1.38551048535346, -1.99204069101103, -1.57679230211392,
-0.821029648, -2.39395151432173, -2.96718943992586, -2.95867282134313,
-2.9175506236826, -2.94755679517459, -2.82290206987746, -2.83914454134393,
-1.84931168689084, -1.94200482386918, -2.56030139156351, -2.4747687889082,
-2.52507434784403, -2.86749990988846, -2.77838660436577, -2.87908253396987,
-2.97385415360498, -2.96244666805069, -2.95752797222193, -2.96426392038595,
-2.93361303993881, -2.91621877029975, -2.97384869333029, -2.96426392038595,
-2.96826157356433, -2.97653443074828, -2.97023260580068, -2.97653534550966,
-2.9715473503959, -2.96240424133875, -2.97289412424858, -2.9730125951007,
-2.86497897723402, -2.93188917574701, -2.89904800305061, -2.6561144854951,
-2.62935195635151, -2.70174255054932, -2.80922741244202, -2.69350740105694,
-2.68242924921473, -2.79295820376613, -2.32657978700299, -2.718248099245,
-2.90625073580661, -2.88407071600265, -2.93759776247538, -2.95143559806685,
-2.87827902655775, -2.83845377816351, -2.15100018436527, -0.392139380784325,
-1.7590965971582, -2.67400272569948, -2.73540774982849, -2.79741598960129,
-2.62741730304073, -2.322499279269, -2.52681590220219, -2.38514457172383,
-2.541507865502, -2.6935934995898, -2.75082409521646, -2.87570553083222,
-2.94427256930162, -2.86349763526591, -2.88884317216564, -2.80553055841713,
-2.47811758528604, -2.55927025907886), OLS_2 = c(-2.83865555876367,
-2.82203271957637, -2.83865550287755, -2.66277932892391, -2.83073328950317,
-2.8182826854432, -2.81275284604234, -2.83069942358793, -2.27571536741022,
-0.632851535784811, -2.56646067709365, -2.55491098827374, -2.02364579120999,
-2.71420058960775, -2.71564453925406, -2.13442002502496, -2.12343285482248,
-0.385841816, -2.74223576659719, -2.83068449367348, -2.83062014186059,
-1.95158880862936, -2.83135434505306, -2.81870405841395, -2.70456098525177,
-2.68251016192609, -1.35080974869909, -1.91966655284606, -1.53026524143009,
-0.821029648, -2.29619548286091, -2.83042962848176, -2.82271365766308,
-2.78489427206998, -2.81254809712918, -2.69700817487578, -2.71212546804251,
-1.78585373408616, -1.87276085874404, -2.45184700668681, -2.37183555552258,
-2.41889982491589, -2.73848954857785, -2.65553364194069, -2.74924637290594,
-2.8354502300085, -2.82614423798244, -2.82167034953476, -2.82594242161564,
-2.7962902949221, -2.77959589724382, -2.83544467118397, -2.82594242161564,
-2.82986834510621, -2.83829410413293, -2.83315419155684, -2.83829521382395,
-2.83312719078141, -2.82412509152621, -2.83447802392599, -2.83561001727694,
-2.73614728712302, -2.79813447119318, -2.76776591170989, -2.54140667394362,
-2.5163996858597, -2.58402223424852, -2.68427373122372, -2.57633280462435,
-2.56598731123967, -2.66911582708562, -2.23311605677819, -2.59943103595799,
-2.7744383205277, -2.75387620457868, -2.80339428073398, -2.81610308322424,
-2.74850042856033, -2.71148276169435, -2.06864445166113, -0.418358709691658,
-1.7012556906544, -2.558117011201, -2.61544592452239, -2.67326984561107,
-2.5145916492569, -2.22929491666958, -2.42052887445801, -2.28795076147412,
-2.43427089501948, -2.57641320261571, -2.62982944259216, -2.74611100908034,
-2.80953310903525, -2.73477077084888, -2.75830410348864, -2.68083005992821,
-2.37496906485549, -2.4508827380889), OLS_3 = c(-2.58083646581942,
-2.5683178338716, -2.58084089114316, -2.41826149362172, -2.57232965672457,
-2.56041470241702, -2.55521822468909, -2.57229650627193, -2.0704676472292,
-0.605591599496051, -2.34899840070827, -2.33897223601076, -1.87552769159633,
-2.47676312148376, -2.46615920192222, -1.94404642215785, -1.9342224786085,
-0.385841816000001, -2.49034777076914, -2.57529735049815, -2.57524652934739,
-1.81248137667339, -2.57293885513887, -2.56558300171966, -2.46846711008925,
-2.44946096338359, -1.28602268062379, -1.78454238349805, -1.4433981562183,
-0.821029648, -2.11368273887782, -2.57509593622485, -2.56887479307252,
-2.53722183306237, -2.56048377359198, -2.46196139684977, -2.47497795642607,
-1.66737628649693, -1.7434807939705, -2.24936019247138, -2.17965685727221,
-2.22066956504207, -2.49762425675709, -2.42616435450559, -2.50683929408026,
-2.57704694280319, -2.57166448720316, -2.56802106429762, -2.56769302344379,
-2.53990559282486, -2.52451787208599, -2.57704119998386, -2.56769302344379,
-2.57148502596854, -2.58019625622877, -2.57722566059429, -2.58019772985789,
-2.57469359055957, -2.56595475982599, -2.57605200249485, -2.57907626550515,
-2.49561557851369, -2.54841138215235, -2.52265924802504, -2.32724456926626,
-2.30551521644622, -2.36423571438323, -2.45098235381054, -2.35756515622,
-2.3485875529132, -2.43789928063234, -2.05861713726078, -2.37759686441414,
-2.52834152993493, -2.51080007744427, -2.55283331443161, -2.56343418632904,
-2.50620082129485, -2.47442497328161, -1.91488441727801, -0.467310795744689,
-1.59326539683083, -2.34175573481226, -2.39147445613669, -2.44148615865099,
-2.30394357612981, -2.05528024243402, -2.22208856552246, -2.10648769733616,
-2.23405702128991, -2.35763491117015, -2.40392966200837, -2.50415507637054,
-2.55797145858227, -2.49443477420494, -2.51458468009137, -2.44801138045477,
-2.18238842077399, -2.24852076027753), OLS_4 = c(-2.4289478285331,
-2.41681903415288, -2.42895104301202, -2.27867081965274, -2.4213161496905,
-2.41038194422522, -2.40559515788832, -2.42128586809391, -1.95522949388955,
-0.590647453749078, -2.21077815389366, -2.20138321248198, -1.76758669368012,
-2.33060054299992, -2.32313500877883, -1.83755181381677, -1.82840597739465,
-0.385841816, -2.34557046847711, -2.42346978407977, -2.42342111188123,
-1.70861264386732, -2.42187239429871, -2.41422413566286, -2.32281181955877,
-2.30497392699143, -1.21632553238408, -1.68248005204524, -1.36346128591018,
-0.781669317752002, -1.99042352676657, -2.42327691796255, -2.41734804581689,
-2.38744248609079, -2.40939495374384, -2.31670510436427, -2.32892438647688,
-1.57289978140148, -1.64407512538075, -2.11744278294415, -2.05217911016675,
-2.09057710272701, -2.35019495754122, -2.28311871426765, -2.35885543710246,
-2.42560672084754, -2.42000135641999, -2.4165372393818, -2.41707097497419,
-2.39145946177805, -2.3772271125231, -2.42560153071694, -2.41707097497419,
-2.420544236609, -2.42841594588832, -2.4253216199613, -2.42841722040367,
-2.42347169955882, -2.41547562547196, -2.42470587973943, -2.4271143253132,
-2.34830761179908, -2.39799094116799, -2.37373288731684, -2.19039487337143,
-2.17003793409615, -2.22505776553193, -2.30640152341961, -2.21880622042115,
-2.21039315621698, -2.294126428977, -1.93888869626962, -2.23758086989921,
-2.37908034073483, -2.36257901260101, -2.4021644964107, -2.41218787827608,
-2.35825527028976, -2.3284051877118, -1.80440438182757, -0.451087514089169,
-1.50359480720157, -2.20399138892979, -2.25058992243427, -2.29749148286179,
-2.16856567860513, -1.93576601076367, -2.09190575790345, -1.98368936201681,
-2.10311255036163, -2.21887159162467, -2.26226743315126, -2.35633238493592,
-2.407018936, -2.34719820268328, -2.36613768370737, -2.30361375259329,
-2.05473632620086, -2.11665669129059), OLS_5 = c(-2.2911912568638,
-2.28123967681215, -2.29119683586224, -2.14805590207021, -2.28325670505768,
-2.27261386268403, -2.268006850245, -2.28322682471889, -1.84560662105751,
-0.576090713535621, -2.0945064647732, -2.0859234999636, -1.68828464788266,
-2.20368547406672, -2.18986194988925, -1.73587625378362, -1.72735189094969,
-0.385841816, -2.21101101562234, -2.28700200417098, -2.28696051646281,
-1.63411554699496, -2.28380625780731, -2.27896044246845, -2.19661244829441,
-2.18039652225164, -1.18146437845759, -1.6101070827248, -1.31682391434599,
-0.781364138557704, -1.89278224977018, -2.28683751979873, -2.28170279433502,
-2.25507742887343, -2.27469315563211, -2.19106352335337, -2.20216376634672,
-1.50940418054145, -1.57481865165838, -2.00915316980509, -1.94938461398854,
-1.98455653642811, -2.22145418758665, -2.1605019074557, -2.22929361026136,
-2.28754415075922, -2.28401553991566, -2.28099274980288, -2.2790962708342,
-2.25448944582185, -2.24095826297856, -2.28753886744317, -2.2790962708342,
-2.28249611688223, -2.29051254450738, -2.28856644852124, -2.29051401027405,
-2.28539476406181, -2.27754391464367, -2.28663199585719, -2.29003809100396,
-2.21974449731936, -2.26453458741267, -2.24273365564754, -2.0758820670505,
-2.05727208640147, -2.1075473897372, -2.18169509790509, -2.10183883759691,
-2.0941547862828, -2.17052540371127, -1.84552009498619, -2.11897925887711,
-2.2475539961602, -2.23266092019845, -2.26826235385205, -2.27716458812284,
-2.22875067319638, -2.20169236013157, -1.72209385129724, -0.476893951190187,
-1.44569200778405, -2.08830648613957, -2.13084935049209, -2.17358829667077,
-2.05592583172644, -1.84265559786228, -1.98577321824112, -1.88660772323127,
-1.99603456442263, -2.10189853669134, -2.14149931364702, -2.22701080101746,
-2.27258448425562, -2.21873931960315, -2.23587705524471, -2.17915915787995,
-1.95172754860073, -2.00843362344438), OLS_6 = c(-2.14615029819501,
-2.1274826763545, -2.14613692884822, -2.038363166, -2.14482079785526,
-2.13839956793073, -2.1352633011825, -2.14480554064275, -1.77137087834078,
-0.604458131512312, -1.92044345866761, -1.91142894340333, -1.5035051350835,
-2.03720410348948, -2.07364942604987, -1.67230210256299, -1.66457879312031,
-0.427523081653794, -2.09111249534671, -2.1358169999572, -2.13575175544593,
-1.44873737433719, -2.14509683128765, -2.12442374236989, -2.02946586195686,
-2.01185030632841, -0.994510606111227, -1.42450007218492, -1.12983335353955,
-0.596198212559954, -1.7115906309286, -2.13555900800151, -2.12811588444992,
-2.09509015766854, -2.11889016916752, -2.02341958358771, -2.03553614239934,
-1.32305159796573, -1.38891263096519, -1.83141440901763, -1.76969899713653,
-1.80596583024281, -2.05682837956465, -1.99043348930533, -2.06558998487816,
-2.14664801486533, -2.13135448546891, -2.1271468279034, -2.14250449627423,
-2.12545741758249, -2.11509475538252, -2.1466464083569, -2.14250449627423,
-2.14442504670383, -2.14684049810003, -2.13838680613343, -2.1468398441846,
-2.14583791450693, -2.14156460788614, -2.14633891192499, -2.14114136796206,
-2.05492693125432, -2.10632999229998, -2.08080895764288, -1.90090288083161,
-1.88144765246016, -1.93417313784094, -2.01325520240903, -1.9281579797124,
-1.92007377040746, -2.00120005643771, -1.66327168223962, -1.94624457366434,
-2.08634430885867, -2.06937728900294, -2.11086434271986, -2.12206882778948,
-2.06498074945642, -2.03501978622706, -1.5377512452434, -0.29431817292714,
-1.25902518147068, -1.91393009686737, -1.95881793980313, -2.00449939786682,
-1.88004274517372, -1.66034827254381, -1.80722288608151, -1.70526848086161,
-1.81783189921089, -1.92822084254891, -1.97013652098612, -2.0630309651189,
-2.1162243283256, -2.0538104595074, -2.07300962091288, -2.0105124912345,
-1.7721107506457, -1.83066883021211)), .Names = c("Y", "X", "Null",
"OLS_1", "OLS_2", "OLS_3", "OLS_4", "OLS_5", "OLS_6"), row.names = c(NA,
99L), class = "data.frame")
My scatter plot will consist of the first column (Y) and the second column (X).
The third column i will not use.
From the fourth column are the curves that are fitted values of OLS regressions.
How do I include them using the plot function?
i am doing this, but its not working
plot(data[,2],data[,1])
for(i in 4:9){
lines(data[,i])
}
What am i doing wrong?
Basically you want
data <- data[order(data$X), ] ## reordering so that `X` is increasing
plot(data$X, data$Y)
for (i in 4:9) {
lines(data$X, data[,i], col = i) ## remember to set `x-coordinates`
}
legend("topright", legend = names(data)[4:9], col = 4:9, lty = 1) ## add legend

Resources