kriging spatial data, error var1.pred NA - r

hey i have a dataset that contains a z value of several sampling points, i want to interpolate them to an extent which i had created and gridded earlier, but i keep getting NA for my var1.pred value.
Error in seq.default(min(z[valid]), max(z[valid]), length = cuts + 1) :
'from' must be a finite number
In addition: Warning messages:
1: In min(z[valid]) : no non-missing arguments to min; returning Inf
2: In max(z[valid]) : no non-missing arguments to max; returning -Inf
here's the sample of my code.
#convert to spdf
coordinates(VELOCITY2)<- ~ X + Y
wg<-gstat(id='V', formula = V~1, data=VELOCITY2 )
#variogram
vv<-variogram(wg, cutoff=2000, width=100)
print(plot(vv,plot.numbers=T))
#initial variogram model
vm<-vgm(psill=0.02, range=550, model="Wav", nugget=0.005)
print(plot(vv, model=vm))
#fit variogram
vmf<-fit.variogram(vv,vm)
print(plot(vv, model=vmf))
# points to be interpolated
xx<-seq(from=488300, to=493200, by=100)
yy<-seq(from=9839400, to=9843200, by=100)
xy<-expand.grid(x=xx,y=yy)
coordinates(xy)<- ~ x+y
#ordinary kriging
kk<-krige(V~1, VELOCITY2, newdata=grid, model=vmf)
#plot
spplot(kk, "var1.pred")
my dput
structure(list(X = c(491810.00721276, 492328.97433014, 490911.89327549,
491615.51887818, 491615.51887818, 492894.620021, 492151.9979203,
492572.42983547, 492347.61141516, 491363.11382593, 491353.29751125,
492072.93297881, 490716.22127832, 492001.85406044, 492018.98815452,
492077.66253205, 492050.13933868, 490972.9839127, 491655.7778789,
491576.10196219, 492355.7400162, 492297.13259429, 492673.39998931,
492505.61098796, 492938.89101704, 492796.38161778, 492663.73140998,
492766.00027009, 492765.78359527, 491933.88466968, 492333.89864649,
492720.51113432, 492666.86568757, 492667.84225007, 492522.21401529,
492831.86513802, 492878.85586085, 493201.72451331, 492638.4094498,
492819.43215484, 492796.76931284, 492747.65005034, 492788.05373669,
492762.22524575, 492244.6870987, 492264.07015541, 493008.44619315,
492815.19350734, 492290.80611714, 492277.18886875, 493134.10402992,
493079.00698391, 493078.7734634, 491865.03127595, 492051.82525174,
492670.54384925, 492371.64034572, 491846.41277618, 492775.84682769,
492411.87697905, 492638.79940336, 492638.87569731, 492495.60555568,
490338.97585592, 490362.31496736, 490377.77810208, 489826.99294604,
489853.05092929, 489834.89614387, 490306.53786769, 490308.6412613,
489636.52553863, 489814.82046046, 489667.51345374, 490203.52431788,
491203.81484533, 491077.79256743, 491073.15243053, 491084.72133938,
490958.56246482, 490941.8523819, 491050.5864517, 490764.25539687,
490188.41994785, 490419.69106592, 490424.64284814, 490735.1435195,
490387.98623199, 489297.98195959, 489300.76955718, 490397.404689,
489661.53774563, 490894.97121725, 491108.0970718, 491121.07516021,
490612.02505037, 490615.90676419, 490585.43667157, 490603.01613921,
490591.97121732, 490535.56215982, 489776.74367816, 489958.02334144,
490066.17495271, 490031.0577653, 490190.24001607, 490211.20925445,
490214.70901031, 490003.5550795, 490604.9470475, 491123.82247476,
489847.73806302, 489976.32595346, 491294.31450964, 491007.18618313,
490369.37771158, 490354.14687653, 489273.8003189, 493001.10122237,
489539.64309234, 489012.00149085, 489142.87160796, 488409.5044205,
489078.66848285, 488976.293483, 489208.90896154, 489567.98757469,
490259.16079274, 490199.06081707, 490548.30691066, 489506.84939121,
489507.3984635, 489021.03298499, 488958.65896146, 490198.91372226,
489139.35891258, 488770.78518218, 488912.45339509, 488981.85549448,
488921.30666655, 489881.9584, 489672.654689, 489896.83645177,
489617.50564114, 489919.08864898, 489379.67238921, 491965.57000272,
491962.99825592, 492682.55996244), Y = c(9840083.34991902, 9839461.79230204,
9839986.04132536, 9839995.68878658, 9839995.68878658, 9839486.28400126,
9839853.49933327, 9839540.02081761, 9840596.63605199, 9840110.85284895,
9840123.81671612, 9839970.95343491, 9840217.59113002, 9840621.88702863,
9840939.65655981, 9840492.69562223, 9840364.30304425, 9840527.17804416,
9840153.15948959, 9841067.64777074, 9840733.71222385, 9840674.12726294,
9841985.09015356, 9841070.55597392, 9841095.72784893, 9841691.20050513,
9841720.81866902, 9841676.02960665, 9841673.8772629, 9841246.79718484,
9841422.27277072, 9841223.11749737, 9841990.83136454, 9841994.02765366,
9841585.87726301, 9841625.27960673, 9841777.00030985, 9841315.42609103,
9841973.23663798, 9841953.58624746, 9841942.04523162, 9841975.5950365,
9841921.55109098, 9841756.52179438, 9841803.37823974, 9841535.90655976,
9841695.74445044, 9841543.94562221, 9842174.64777079, 9842182.19659889,
9841376.54230196, 9841406.85773171, 9841406.8294114, 9841667.93488034,
9841949.92609129, 9841973.67413798, 9841897.64874747, 9842246.51398172,
9842171.76691117, 9841921.16437243, 9842138.53937229, 9842136.97003635,
9842380.89386459, 9839975.91827856, 9840042.95343491, 9840089.22394263,
9839589.44562232, 9839978.97296608, 9839972.67706767, 9840000.61749732,
9840046.62823938, 9840384.73566135, 9840302.14484109, 9840018.78351297,
9842250.19659889, 9842008.34698953, 9842209.1907394, 9842203.61261452,
9842217.50519284, 9841646.07648174, 9841683.64679432, 9842192.50519265,
9842183.09796603, 9842277.04034879, 9841973.30402079, 9841966.2620286,
9842110.55011467, 9842137.70929444, 9841800.60968466, 9841802.06769271,
9842097.74445065, 9841639.30499731, 9842195.63995834, 9842542.10675523,
9842116.55011473, 9841963.44464579, 9841829.30792699, 9841930.18585674,
9841916.66632539, 9842076.43488016, 9842082.75030963, 9842131.36456766,
9842160.68292699, 9842132.72687234, 9842139.580388, 9842277.19952862,
9842102.06183342, 9842101.63605201, 9842143.56085666, 9842095.04718486,
9841791.23859127, 9842670.9856614, 9843067.83527079, 9841903.34601296,
9841830.02277074, 9843129.77081764, 9843097.71808326, 9842604.47394268,
9840407.78644266, 9841952.95148171, 9842186.80011454, 9842038.18195044,
9841950.33234116, 9841538.57843486, 9842189.03839584, 9842814.41534891,
9842339.88898166, 9841739.39484119, 9841739.58624731, 9841750.17023162,
9842428.79816146, 9842966.83429408, 9841471.2981614, 9842028.5803879,
9841446.35480217, 9841755.92120829, 9842498.21027067, 9842371.99152076,
9842484.98761453, 9842385.0296069, 9840908.95441133, 9840831.87628639,
9842363.49738009, 9842105.66730203, 9842228.79132547, 9842178.55792694,
9840714.60968473, 9841214.43976303, 9842612.580388), V = c(6.8575591273834,
6.9091981717661, 6.81861092653243, 6.83544315031305, 6.83544315031305,
6.86928044706404, 6.87308158923757, 6.90102887370632, 6.93656422063757,
6.82756100389376, 6.8279728230811, 6.86916707425107, 6.88723098934826,
6.80869108780012, 6.81041873685147, 6.84851460419374, 6.83998564798438,
6.95597672440102, 6.84830429624437, 6.83571668853121, 6.81554716876882,
6.81653691949333, 6.86570172920796, 8.4183926299318, 6.82540315375968,
6.83694453186651, 6.83616001733514, 6.83366932709608, 6.83281519168562,
6.80657805425162, 6.79252081867902, 6.82804093704906, 6.86560659062316,
6.86560443487979, 6.81210486339519, 6.83024981887722, 6.85348365590436,
6.82737621767244, 6.86002774823981, 6.87890401083686, 6.87433304662824,
6.87310828011749, 6.87227288578899, 6.8406970455203, 6.79788666568234,
6.79289704147439, 6.84212179617635, 6.82201406577053, 6.85818255251501,
6.85882147766148, 6.81441839578817, 6.81109679654478, 6.81075562992338,
6.7695290140362, 6.78453986430733, 6.86470017777305, 6.82941505329464,
6.80201545646814, 6.89940111534327, 6.83386524913627, 6.88022016259413,
6.88000932400808, 6.89652613707228, 6.80951701420202, 6.81047007954082,
6.91318917468862, 6.81620742405261, 6.81609592365983, 6.81555114576811,
6.82359364040975, 6.82243031847043, 6.74848377545697, 6.77432742350875,
6.82113095074504, 6.73035636876622, 6.73157311534001, 6.68948620878327,
6.68804994926179, 6.68991058622174, 6.82298306298922, 6.79655085098109,
6.67806113435277, 6.67880893125878, 6.67462932793097, 6.76784233910405,
6.76791677619622, 6.68328242293505, 6.62279457979837, 6.80333643693172,
6.8017836170837, 6.74582126343433, 6.89705699013895, 6.67169623224357,
6.71095156872004, 6.70398418262631, 6.74214143831379, 6.77269747758851,
6.75839168452443, 6.75917136037271, 6.72567955117309, 6.72476400985706,
6.7940929187327, 6.76465011146018, 6.76185819997855, 6.76483265829331,
6.73217398985043, 6.7558472215621, 6.75644688026535, 6.76569985187991,
6.72096268409918, 6.79914751724536, 6.73903734858573, 6.76387478912845,
6.75057145302792, 6.78523214680787, 6.80514090870779, 6.79610181104104,
6.94632505323771, 6.87151617920864, 6.73501760825965, 6.8043110280055,
6.76237168672284, 6.87393143300434, 6.77223974414773, 6.81073018103125,
6.87291116726081, 6.85121557850258, 6.84429643254038, 6.71871340520001,
6.80737642861958, 6.87505551354325, 6.78810343307566, 6.77795244044547,
6.80445829734336, 6.96781526094347, 6.85340711647284, 6.86963847089039,
6.81734050576888, 6.79958184646059, 6.81761012476222, 7.11505624553277,
7.10405850051035, 6.74511681211045, 6.82787357725889, 6.75689662271503,
6.75616848941266, 6.82089585076081, 6.81664705027901, 6.91617186341967
)), .Names = c("X", "Y", "V"), row.names = c(NA, -149L), class = c("tbl_df",
"tbl", "data.frame"))

Related

Understanding why I get an error in computations when removing certain columns gives zero error: library(lpSolve)

I understand that this question has been asked before but I could not solve the question with the current solutions after searching.
I am running into an error:
Error in solve.default(covs) :
system is computationally singular: reciprocal condition number = 1.08804e-18
Code: (which give the error)
library(lpSolve)
retbar <- colMeans(rets, na.rm = T)
covs <- var(rets, na.rm = T) # calculates the covariance
invS <- solve(covs)
Other:
> det(covs)
[1] 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003458185
> qr(covs)$rank
[1] 20
However when I remove some variables and run the code it works....
Code2: (which works)
rets$B6 <- NULL
rets$M6 <- NULL
rets$R6 <- NULL
rets$Q6 <- NULL
retbar <- colMeans(rets, na.rm = T)
covs <- var(rets, na.rm = T) # calculates the covariance
invS <- solve(covs)
> det(covs)
[1] 0.000000000000000000000000000000000000000000000000000000000000000000000000003514001
> qr(covs)$rank
[1] 20
I just want to understand why removing "X6" variable from my data allows me to solve the cov matrix. I have seen that "X6" (X here is B,M,R,Q) is correlated with other variables - "X6" is calculated as "X5 - X1" (or: B5 -B1, M5 - M1, R-5 - R1, Q5 - Q1") - I would like to idealy keep all columns in the data.
Data:
EDIT: New df
rets <- structure(list(B1 = c(0.0201596769556875, 0.00796992085297743,
0.0492147329548896, 0.019344865533839, 0.0215214485329025, 0.0207218693128776,
0.0103862072924815, 0.0140747415980048, 0.0261785500777131, 0.0373946762995772,
-0.00684759663692184, -0.0524902194742576, 0.00315800118629925,
0.0311087399558667, 0.0296245772665513, -0.0714423815378389,
-0.00828133058937649, -0.0474562526488911, -0.027177578320533,
-0.0150494495620104, 0.0348119470955449, 0.026557944400082, -0.0948970420281616,
0.020249494359762, 0.0362642768918328, -0.108930302464037, -0.209399350620045,
-0.131078973014079, 0.0340021699340833, -0.0392411420552388,
-0.104669817843903, 0.126868769506696, 0.180232948671053, 0.0769264211043898,
0.019176729939273, 0.0993469049194573, 0.0738823618605167, 0.0686517377053094,
-0.0438445535170806, 0.0291731714634921, 0.074704119945333, -0.00156713313391479,
0.041919134266091, 0.0718713711298, 0.0616824041447802, -0.0694331912797978,
-0.0664994905875237, -0.0637350113576239, 0.0995459645599069,
0.0350470019423567), B2 = c(0.0159402689787551, 0.0162507344633192,
0.0740337591014227, 0.0384769820770539, 0.0091777285515574, 0.0266077913225889,
0.0135757617808849, 0.00407485086602279, 0.024561373325238, 0.0369076019690258,
-0.0111998096779211, -0.0550216348217377, 0.00296776607315141,
0.0155911183644963, 0.0127829585460845, -0.0686988206697129,
-0.0120169929067047, -0.0379441518196964, -0.00997556953482333,
-0.0157591765829324, 0.0259378688367708, 0.0348720134553493,
-0.0864851422178537, 0.0243151482365286, 0.054450975569433, -0.105384283400191,
-0.244132080369671, -0.149214851674911, 0.0642730083371614, -0.0732165541787947,
-0.132146613068358, 0.117037257468365, 0.243486361548774, 0.127689400206569,
0.0507680353897798, 0.0918127231182545, 0.057623460462537, 0.0664555639592365,
-0.0637209916042463, 0.0351111011481844, 0.0774253568342104,
-0.0208447613007578, 0.0464411219167523, 0.088343873921378, 0.0845804848931461,
-0.0672340736611374, -0.063074008563108, -0.0552850698211716,
0.118020745550881, 0.0350453682926441), B3 = c(0.0254691625247841,
0.0122239330016886, 0.0446599436180717, 0.0289436320423226, 0.00984126934358344,
0.0248495851877287, 0.0070023062540998, 0.00867717868910234,
0.0198468884639984, 0.0423526987264829, -0.00673483175868612,
-0.0536716292198917, 0.00702602564601019, 0.0161515106339872,
0.00881414723751897, -0.0704128768108256, -0.0118703057246587,
-0.0654796158401091, -0.0214858440189339, -0.0287089650155394,
0.0375015423973781, 0.0669904486938052, -0.0941557378605896,
0.0153425838301645, 0.0209397917472626, -0.101627763946357, -0.226324878317675,
-0.141233587277128, 0.0562599340844954, -0.0426624056954274,
-0.101409613365061, 0.095072163016385, 0.19560509325657, 0.153377825232805,
0.0250685160313996, 0.0912032732747058, 0.0514030426458047, 0.0803912808233686,
-0.0604690113263003, 0.0268422517753881, 0.10412185199629, -0.0227046178907074,
0.045247514742643, 0.080985450832222, 0.0646318077059794, -0.0703469469216747,
-0.0487479424020042, -0.0677789445266782, 0.102936536920121,
0.0372798264656416), B4 = c(0.0219191738217161, 0.0176853257846887,
0.0456353457446462, 0.0341367113786865, 0.0224113039756616, 0.0198275955536373,
0.00679047712618314, 0.00326894704835364, 0.0279149805055439,
0.0270857608217435, -0.00413393714898988, -0.0566739462091404,
-0.0114439339594225, 0.011077534748248, 0.0166466370578447, -0.0733647442632695,
-0.0100085083715353, -0.0525145185232886, -0.0326582904953551,
-0.0193272575954162, 0.028187178228298, 0.037490075562138, -0.0740065271333753,
0.0376882236271473, 0.0170308927355229, -0.0991359056176541,
-0.224423397219161, -0.118318357393019, 0.0765578429241032, -0.0580225262433487,
-0.110441975119102, 0.101623526281797, 0.208245933500372, 0.0931300452658907,
0.0371493076663389, 0.109834174058939, 0.0451845252205385, 0.0922986324245771,
-0.0604417879228685, 0.0176772270368012, 0.0760699055274017,
-0.0219431067610276, 0.0363180693269241, 0.10978144288715, 0.0703026600940392,
-0.0827017008478804, -0.0577866241297221, -0.0682246277864018,
0.112824937430707, 0.042166109959073), B5 = c(0.0393541248460465,
0.00956169994553254, 0.045506941231113, 0.022679161458704, 0.0071175687346599,
0.0245724846722118, -0.00486326015007488, 0.00977777199018314,
0.0372227348807343, 0.0421686696514302, -0.00729705359364536,
-0.0420398232585704, -0.00198560837531052, 0.0191012049979939,
0.0151182378767174, -0.0720890664222317, -0.0145999296151926,
-0.0549852597740717, -0.0357418224487, -0.00858510372461121,
0.0371052230990963, 0.0358706764622103, -0.0797211143737148,
0.0133179042163717, 0.0227502855968991, -0.0960364954219236,
-0.20877985810845, -0.125247884467955, 0.0582827803341161, -0.0546479539249937,
-0.127419512889315, 0.161520030974712, 0.213080660094016, 0.108923963868525,
0.0216324723000225, 0.123493437786137, 0.0643989332634697, 0.065803254107272,
-0.0624072744596408, 0.0370168039973202, 0.0836690142031841,
-0.0128692586306809, 0.0506633041324735, 0.0963571736706436,
0.0704426407884252, -0.0733420360542838, -0.0710357171347283,
-0.0688377671567964, 0.132571567141589, 0.0447762558807919),
B6 = c(0.019194447890359, 0.00159177909255511, -0.0037077917237766,
0.00333429592486495, -0.0144038797982426, 0.00385061535933419,
-0.0152494674425564, -0.00429696960782166, 0.0110441848030212,
0.00477399335185296, -0.000449456956723525, 0.0104503962156872,
-0.00514360956160977, -0.0120075349578728, -0.0145063393898339,
-0.00064668488439279, -0.00631859902581606, -0.00752900712518056,
-0.00856424412816701, 0.00646434583739916, 0.00229327600355132,
0.00931273206212835, 0.0151759276544468, -0.00693159014339035,
-0.0135139912949337, 0.0128938070421132, 0.000619492511594932,
0.00583108854612438, 0.0242806104000329, -0.0154068118697549,
-0.0227496950454118, 0.0346512614680161, 0.0328477114229624,
0.0319975427641352, 0.00245574236074952, 0.0241465328666802,
-0.00948342859704696, -0.00284848359803735, -0.0185627209425603,
0.0078436325338281, 0.00896489425785109, -0.0113021254967661,
0.00874416986638248, 0.0244858025408436, 0.008760236643645,
-0.00390884477448601, -0.00453622654720459, -0.00510275579917252,
0.0330256025816826, 0.00972925393843514), M1 = c(0.0113396747037768,
-0.036155735142529, 0.0550687853246927, 0.0269238017499447,
0.00982287898659706, 0.00809061527252197, -0.047512024641037,
-0.016009446233511, -0.00278357416391373, -0.00628054095432162,
-0.0609199032187462, -0.0494923722396639, 0.00698078286246139,
0.00983662394804645, 0.0380059639114982, -0.0652908706460783,
-0.00563693966137906, -0.0491752210641838, -0.0214304637710383,
-0.0153438172807354, 0.0203537379326515, 0.0421207453446271,
-0.083814601712769, 0.0152837951106913, 0.031787003709805,
-0.107241585677281, -0.210874717399826, -0.115555851834153,
0.0599437241751638, -0.0587498251989018, -0.0995314111424103,
0.104148721637336, 0.182319135902193, 0.105787461175244,
0.033689877375748, 0.0966363048202885, 0.0640538126301515,
0.0640782744095522, -0.0440799278693556, 0.0303018999590801,
0.0841023643583563, -0.0176897923202359, 0.0382914170044418,
0.0759079900327234, 0.0738894489211014, -0.0566797658200011,
-0.0592523659979936, -0.0605415574124922, 0.108837738508142,
0.0311480459267166), M2 = c(0, 0.0369318500161171, 0.05479446798563,
0.0441558659076691, 0.0063580423593521, -0.0073090447112918,
-0.0191763313487172, -0.00646415911614895, 0.0458552502095698,
0.0275424104183912, -0.0487805381417274, -0.0400584393734526,
-0.00416827541765468, 0.0212708574224962, 0.0174144436427715,
-0.0674113624348997, -0.0125841060695098, -0.0558416555270291,
-0.0163345211185515, -0.0219548647100168, 0.0504916901610439,
0.0417230815077788, -0.0769711063634779, 0.0167976787218786,
0.0430265647426742, -0.123826423650743, -0.234415110641567,
-0.130708167875127, 0.0554669174895657, -0.0450817684669273,
-0.12032524188012, 0.154298987141929, 0.236011380184834,
0.114111615690755, 0.0275421794934158, 0.0938332458107501,
0.0953365754115465, 0.0847282442055681, -0.0712375521873279,
0.0174096324909712, 0.0755245202122583, -0.00762107035320276,
0.0428905926947967, 0.0972422302671232, 0.076027299598966,
-0.0788738990751014, -0.0621384863719475, -0.0624743295694587,
0.116711918883773, 0.0476898780038488), M3 = c(0.0359311569482088,
-0.139999955892563, 0.0209301561117172, 0.104783609509468,
-0.0721649304032326, 0.397777765989304, -0.0111288027837873,
0.00482318503782153, 0.14879997074604, 0.16648281365633,
-0.0580596011132003, -0.047679182583228, 0.0114269531841602,
0.0317433578864438, 0.00775221147687179, -0.061602244912588,
-0.0158776681251565, -0.0648263710640019, -0.0240124892502704,
-0.0177448932428571, 0.0379559719894449, 0.0344511040566261,
-0.0775795445422815, 0.027065822418437, 0.0251577377516715,
-0.108475149947571, -0.235411574529894, -0.144522154940724,
0.0449754514928253, -0.0489695645129837, -0.123624581783743,
0.11508095146038, 0.211242172822533, 0.145198421859061, 0.0179784820325099,
0.0982173541566308, 0.0555486086463638, 0.0736606557016785,
-0.0583725513432673, 0.0363466235082538, 0.0690110039168571,
-0.0160342605855651, 0.0540222033909931, 0.0862467848463471,
0.0633677104077289, -0.0850614424954192, -0.0535852042349274,
-0.0603007163253751, 0.113070077846931, 0.0408424520012463
), M4 = c(-0.155844137072563, -0.0610789265483618, 0.0988630047067999,
-0.0086556291207671, 0.0815064907073975, -0.0185706592164934,
-0.0207591075450184, 0.105547562241554, -0.107201084494591,
0.0113929212093353, -0.022529099136591, -0.0441186886312525,
0.00195441980877977, 0.016870060442579, 0.00759373951839394,
-0.0769912599379698, -0.0171198804233096, -0.0417608516722064,
-0.0238246997368977, -0.0177104066632295, 0.0235756050630395,
0.0269268993848493, -0.0967296211775303, 0.0324606583258286,
0.0290416693746976, -0.092120191410525, -0.230766838669409,
-0.140616977306715, 0.0699212552919189, -0.0613821172279649,
-0.129080012361016, 0.115632295353163, 0.241743159430643,
0.0945421887374065, 0.0330785879111653, 0.114030935722985,
0.0394783260686381, 0.0637947810755577, -0.060909434465672,
0.0323739642311314, 0.0841339563067396, -0.0184345132038895,
0.0495400154798214, 0.0976821368464078, 0.0614972022290451,
-0.0706658855287132, -0.070385725555342, -0.073441507572736,
0.109315224489104, 0.0374856931309638), M5 = c(-0.12346476316452,
-0.0105703119188547, 0.092919297516346, 0.136621922254562,
-0.0155999753624201, 0.0682649463415146, -0.0922404378652573,
0.0620875768363475, -0.0615064632147553, 0.143709745258093,
0.0756230279803276, -0.0617075127175431, -0.00360911323150503,
0.0112366336242249, 0.0154406559539872, -0.0787746054515343,
-0.00269523979941826, -0.0526490888305032, -0.0326128715360069,
-0.0167875265945536, 0.0288873225335168, 0.0437001503452364,
-0.0850432923719407, 0.0182440995488183, 0.0238926558011993,
-0.0957959717629556, -0.215013577753659, -0.144644269534711,
0.0501889619753152, -0.05768291939606, -0.128211720987334,
0.127069415092379, 0.216602876296358, 0.113530188173674,
0.0468711288658715, 0.122424450357045, 0.0374143540121529,
0.0871767761121666, -0.0567737247714127, 0.0360353329323981,
0.103461599696569, -0.0225164942232245, 0.0415910101081693,
0.0918531230749919, 0.0755528541988306, -0.0728917148203065,
-0.0657610368590244, -0.0564028779478209, 0.122215778161083,
0.045920382671152), M6 = c(-0.134804437868297, 0.0255854232236743,
0.0378505121916533, 0.109698120504617, -0.0254228543490172,
0.0601743310689926, -0.0447284132242203, 0.0780970230698586,
-0.0587228890508416, 0.149990286212415, 0.136542931199074,
-0.0122151404778793, -0.0105898960939664, 0.00140000967617841,
-0.0225653079575109, -0.0134837348054559, 0.00294169986196079,
-0.00347386776631942, -0.0111824077649687, -0.00144370931381818,
0.00853358460086529, 0.00157940500060929, -0.00122869065917164,
0.00296030443812702, -0.0078943479086057, 0.011445613914325,
-0.00413886035383279, -0.0290884177005585, -0.00975476219984855,
0.00106690580284179, -0.0286803098449235, 0.0229206934550435,
0.0342837403941652, 0.00774272699843015, 0.0131812514901235,
0.0257881455367569, -0.0266394586179985, 0.0230985017026144,
-0.0126937969020571, 0.00573343297331802, 0.0193592353382127,
-0.00482670190298854, 0.00329959310372758, 0.0159451330422685,
0.00166340527772912, -0.0162119490003055, -0.0065086708610308,
0.00413867946467136, 0.0133780396529413, 0.0147723367444354
), Q1 = c(0.0265621797051281, 0.0121992440563654, 0.0340947461024625,
0.0114726169959482, 0.0244721697934678, 0.0304556573852703,
-0.00256444356341105, 0.00372350399549636, 0.0237739984235116,
0.0270033285140239, -0.00704723803210073, -0.0476901397804718,
0.0071129609034004, 0.0323939519651734, 0.00323882454019589,
-0.0622794850397196, -0.0119234506451499, -0.0399236912960561,
-0.0436079844051925, -0.0261022150048638, 0.0291371183325865,
0.0563959058031636, -0.0907071155080928, 0.013374178530945,
0.0681693173169967, -0.0880869802416643, -0.218258767247561,
-0.138316280509299, 0.0411314660955931, -0.066409005195869,
-0.139430000425292, 0.101716784591166, 0.199285888061083,
0.0893195469347605, 0.0207835902897264, 0.0819590143972909,
0.0428754482336569, 0.0804621560497635, -0.0576983031786784,
0.026600132264742, 0.0760024661290204, -0.0281950326994129,
0.0424528139477703, 0.0865725399565793, 0.077255839460645,
-0.0690729842646359, -0.0617721764311835, -0.0619110102090971,
0.0975149637737052, 0.0422298654882387), Q2 = c(0.0265492763632932,
0.0222894305734672, 0.0476030515586719, 0.0257378459646134,
0.0255000609197377, 0.0300794550319551, 0.0133745468006092,
0.0187672452778894, 0.0248004048250247, 0.0205707288256205,
-0.00587681182154011, -0.0630040478242402, 0.000107261570787615,
0.00467345834692457, 0.0213892270033362, -0.0937099313495658,
0.00251645909947125, -0.0632956599325149, -0.00132090380066074,
-0.031540190910209, 0.0415217259003839, 0.0196243224662538,
-0.0976611527880924, 0.01713131867179, 0.0206693921571488,
-0.10984720875515, -0.23604335413059, -0.123298519500156,
0.102579391798905, -0.0619608930031467, -0.122741970750742,
0.107440420011137, 0.258562571065352, 0.0831288756533286,
0.0380738103365828, 0.102122914387041, 0.0771691647838361,
0.0869058388988892, -0.0542813220308744, 0.0351488706963522,
0.0846733840829011, -0.0167029370619785, 0.0380128870131627,
0.0954233112213096, 0.059146453231235, -0.0675340663722515,
-0.0772898672570218, -0.0756378709511565, 0.134937047612454,
0.0226618044495643), Q3 = c(0.0249571957657415, 0.0296065641893266,
0.0516467535933711, 0.0204032773069533, 0.00564130011432592,
0.0224283534635712, 0.00301239166268108, -0.000150963898842058,
0.0229134533635214, 0.0424657574061316, -0.00777680567175671,
-0.0445223698536066, 0.00394081997679386, 0.0240830812307228,
0.0124971211046563, -0.0795800732459543, -0.00881168550209076,
-0.0584900388668757, -0.0263079088348604, -0.0200931730088996,
0.0449965138077459, 0.0368462420389372, -0.114047989403222,
0.0267671234829322, 0.0151821869391063, -0.111191677522722,
-0.204383997931583, -0.126313542632778, 0.0672104859243762,
-0.0666682464928415, -0.0980276147276163, 0.109471163679627,
0.194550998802703, 0.0833334999543796, 0.0343969262838429,
0.0992981119758178, 0.0528223219283973, 0.0674760505087006,
-0.0665537698263506, 0.0342528662929908, 0.0958234167504998,
-0.0294131255411294, 0.0476092755160584, 0.0909138728225699,
0.0727903652909526, -0.0637077652670556, -0.0656483788804145,
-0.0551227529131964, 0.116486035743042, 0.0356988697476277
), Q4 = c(0.0327908558900147, -0.00581402105550901, 0.0471795087541677,
0.0316287353740667, 0.0154292859732494, 0.0321233577293451,
0.0178516903431687, 0.0297250315289144, 0.0497392455796797,
0.0539487711478713, 0.00185283865199054, -0.0550304813356512,
0.0242636750567233, 0.0215392546950305, 0.0293588232816546,
-0.0724868968014562, -0.000755860281788007, -0.0471606758364942,
-0.0207128138943517, -0.0165231425832055, 0.0434456925169798,
0.0391054884659545, -0.0742084088275147, 0.017590121803775,
0.0469003681911008, -0.096158440258061, -0.226202925207553,
-0.115346873402837, 0.0553655066805321, -0.0526318049432673,
-0.0854428438991429, 0.154789113362523, 0.20641849783792,
0.178990423471939, 0.0210107589738628, 0.1585673924883, 0.0698894288055367,
0.109538887119296, -0.0571717024643894, 0.0429703488688447,
0.0646785154424408, -0.0175924605503971, 0.0516479415292585,
0.106135927417663, 0.0894213136540906, -0.0842766439587239,
-0.0607679109495784, -0.064878143379156, 0.12349074462156,
0.0383776279423885), Q5 = c(0.0277489582011476, 0.0194428538125939,
0.0464771821653864, 0.0257204433555745, -0.000805859957640792,
0.0258752236753201, 0.00169526561907242, 0.00845686232849219,
0.0248138846673567, 0.0499029147276336, -0.026119026588276,
-0.0506759613875208, -0.0186567955284256, 0.00666071759448302,
0.00540296976899718, -0.0716488022451813, -0.0217757529500649,
-0.0338310975042987, -0.0341928029469273, -0.0223690567604255,
0.02094411401049, 0.0387905936222523, -0.0834270093258965,
0.0341064407380287, 0.00713508490452064, -0.127295832074014,
-0.237585142941304, -0.13633100805025, 0.0404317628621166,
-0.0701342930682682, -0.154994464337936, 0.137138389891867,
0.266473867978314, 0.149346235523739, 0.0512020926289552,
0.0972987430985086, 0.046678198308291, 0.0691887409841002,
-0.0483228606644157, 0.0438380166785084, 0.108567878481663,
-0.022344000031356, 0.0458931252688222, 0.0821382803979602,
0.0776712501269335, -0.0782288163911569, -0.0717866494829638,
-0.0441555801962854, 0.113855257071555, 0.0431730594966379
), Q6 = c(0.00118677849601953, 0.00724360975622851, 0.0123824360629239,
0.0142478263596263, -0.0252780297511086, -0.00458043370995016,
0.00425970918248347, 0.00473335833299583, 0.00103988624384509,
0.0228995862136097, -0.0190717885561753, -0.00298582160704901,
-0.025769756431826, -0.0257332343706903, 0.00216414522880129,
-0.00936931720546169, -0.00985230230491503, 0.00609259379175739,
0.00941518145826525, 0.00373315824443837, -0.00819300432209647,
-0.0176053121809113, 0.00728010618219631, 0.0207322622070837,
-0.0610342324124761, -0.0392088518323502, -0.0193263756937437,
0.00198527245904931, -0.00069970323347647, -0.00372528787239923,
-0.0155644639126446, 0.0354216053007016, 0.0671879799172312,
0.0600266885889786, 0.0304185023392288, 0.0153397287012177,
0.00380275007463411, -0.0112734150656633, 0.00937544251426276,
0.0172378844137663, 0.0325654123526421, 0.00585103266805692,
0.00344031132105193, -0.00443425955861904, 0.000415410666288515,
-0.00915583212652102, -0.0100144730517803, 0.0177554300128117,
0.0163402932978495, 0.000943194008399206), R1 = c(0.0182182283776942,
0.0133596019044421, 0.0432659004262889, 0.0221001061009796,
0.0105907624828407, 0.0239597644983188, 0.000582050596458943,
0.014147774983186, 0.0234533732901644, 0.0317608721171364,
-0.0166806564027188, -0.052434190706138, 0.0100713259540498,
0.0101734290645623, 0.0288354928293034, -0.0605050812338745,
-0.0117308063666151, -0.0572323586752662, -0.0272877553780779,
-0.0120147655606391, 0.0419646855503247, 0.0324565952813083,
-0.0993208162860145, 0.0395097806733453, 0.0238556437261408,
-0.114658174673633, -0.2195395447872, -0.137508094828707,
0.074964741726552, -0.0604685437878159, -0.111606039290815,
0.136833144806414, 0.222703023385423, 0.0841373058009376,
0.0141210132573047, 0.0945658775885383, 0.0720258311603175,
0.072218863181222, -0.0464783244216175, 0.0196372191978457,
0.0764585826402174, -0.0109085058330569, 0.0359374463515418,
0.0818041172339742, 0.0660486282980199, -0.0707042835229565,
-0.0683338724528508, -0.0610787198706517, 0.10245202132339,
0.0336024502788171), R2 = c(0.0191115892525381, 0.0213770552106516,
0.0495591080020083, 0.0217964101541805, 0.0144038778845475,
0.0184814835192124, 0.0105638044882981, 0.0169188201074749,
0.0276594408901124, 0.0348981320533056, -0.00601471285249273,
-0.0742367928195745, 0.00395378441574753, 0.0204693427515786,
0.0119432134599844, -0.0874038103063021, -0.0151874175793209,
-0.0472985114867765, -0.0280096128634695, -0.0160812378016462,
0.0321308743545342, 0.040546940059076, -0.0948356372283535,
0.0107826096321911, 0.0257959865133892, -0.111356276103297,
-0.231763659704638, -0.114593808207563, 0.0521066918649241,
-0.0585007082261173, -0.109123376446412, 0.126602824255329,
0.173736381165564, 0.199924017362175, 0.0481556947170322,
0.0973811981639015, 0.0359796749373038, 0.0813126198664245,
-0.0512295355950761, 0.0279254079344163, 0.086866979370594,
-0.0192548779536499, 0.0447691648075989, 0.0862634325791489,
0.0697143276875948, -0.0692263805833664, -0.0500105867630836,
-0.0588590458196327, 0.106730721635263, 0.0421188281435415
), R3 = c(0.0127029458612358, 0.0018533759915124, 0.0760172229180238,
0.0367249979117247, 0.0150598922914917, 0.0336805265497945,
0.00793725637078958, 0.00747404394924289, 0.0274879617237065,
0.043333103669918, -0.00161559239160282, -0.0455316266423957,
-0.00214711870702203, 0.0248726461836401, 0.00653189279270605,
-0.0578474430051428, -0.00753182224084245, -0.0497961950688571,
-0.0215957843383809, -0.0186999944968934, 0.0484307593124901,
0.0311984415753566, -0.0821598079518168, 0.0100672285713556,
0.0372802787529577, -0.104028042014104, -0.222058497109385,
-0.147313185333738, 0.058569009115331, -0.044662665977512,
-0.109997225946555, 0.0740040206123078, 0.240124115068233,
0.0658274676989834, 0.0230167129023561, 0.0893684046831913,
0.0691791022696998, 0.0935037055760548, -0.0623467636644952,
0.0443609426523667, 0.0841050150254741, -0.010595198663421,
0.0531204943650837, 0.0889886676318655, 0.0717397607923485,
-0.0666121329043526, -0.0679554782502061, -0.0619185083705071,
0.113668574986972, 0.0426805703464197), R4 = c(0.0380760367129327,
0.0177375553170367, 0.0434032638099822, 0.0288078728030292,
0.00992978596216649, 0.0292202896891021, 0.0000603359551190975,
0.0159922639270591, 0.0343884360605202, 0.0439464803116257,
-0.0138187383575441, -0.0420847227142335, -0.00232802864713809,
0.0234398999431073, 0.0192280943826554, -0.0652622771727051,
-0.0129287081223056, -0.0621169225429621, -0.0188534586231707,
-0.0144850139328243, 0.0297268555763311, 0.0285599283377065,
-0.0822735971636855, 0.0204183204990269, 0.032745768708656,
-0.105603577501441, -0.221743181027705, -0.13083768618741,
0.0451022094242408, -0.0511348958540317, -0.117597592112605,
0.135103916679692, 0.220409599165432, 0.123643858561056,
0.0412763113887445, 0.114076890036475, 0.0618001339957569,
0.0751807434389775, -0.0761590390584388, 0.0367453217535741,
0.0741501663098758, -0.0209351147382463, 0.0423510899687777,
0.100368821441917, 0.0695076535685885, -0.0721797128413838,
-0.0600897558968101, -0.0664215180686919, 0.128039957194454,
0.0470262161757679), R5 = c(0.0392411376774867, 0.0154176355104196,
0.040917916701852, 0.0218273582628919, 0.0129334794884874,
0.0272767829214404, 0.00362824471430165, -0.000676154777673734,
0.0324915392070016, 0.0312519866611661, -0.00752454226284161,
-0.0479068156734558, 0.00623306676125675, 0.0175638068591043,
0.0180622711059288, -0.0716966531562826, -0.0105557651114313,
-0.0470363381042701, -0.0319284024370003, -0.0274867890109039,
0.0328552378238075, 0.0503210109454812, -0.0847538417074522,
0.0213618251884607, 0.0268119067996639, -0.0900801570280097,
-0.229113867007717, -0.128659614134882, 0.0757805549254453,
-0.0540399315416828, -0.121830787213285, 0.122317733604241,
0.218198170804459, 0.0991190501510919, 0.0380010340764608,
0.119750604540555, 0.0560657704951905, 0.0599450854028368,
-0.0472973800122937, 0.0261746785776476, 0.0965835597718561,
-0.025910690013656, 0.0420420706295301, 0.101981995863621,
0.0648998978320577, -0.0930218340085276, -0.0682703531336771,
-0.0717185642128733, 0.123732482524253, 0.0358365680790375
), R6 = c(0.0210229092997925, 0.00205803360597752, -0.0023479837244369,
-0.000272747838087638, 0.00234271700564669, 0.00331701842312161,
0.00304619411784271, -0.0148239297608598, 0.00903816591683728,
-0.000508885455970276, 0.00915611413987719, 0.00452737503268219,
-0.00383825919279309, 0.00739037779454201, -0.0107732217233747,
-0.0111915719224081, 0.00117504125518384, 0.0101960205709961,
-0.00464064705892239, -0.0154720234502648, -0.00910944772651717,
0.0178644156641729, 0.0145669745785623, -0.0181479554848846,
0.00295626307352316, 0.024578017645623, -0.00957432222051705,
0.00884848069382546, 0.000815813198893262, 0.00642861224613316,
-0.0102247479224694, -0.0145154112021735, -0.00450485258096373,
0.0149817443501543, 0.0238800208191561, 0.0251847269520169,
-0.015960060665127, -0.0122737777783852, -0.000819055590676188,
0.00653745937980193, 0.0201249771316388, -0.0150021841805991,
0.0061046242779883, 0.020177878629647, -0.00114873046596223,
-0.0223175504855711, 0.0000635193191737132, -0.0106398443422216,
0.0212804612008627, 0.00223411780022038)), row.names = c(NA,
-50L), class = "data.frame")
Firstly, nothing in the question has anything to do with lpSolve or with retbar so please remove this junk from the question.
covs is singular so it cannot be inverted. Note the essentially zero eigenvalues below. Evidently the columns that are linearly dependent on the remaining columns are those set to NULL so removing them eliminates the singularity. If a Moore-Penrose generalized inverse is sufficient then MASS::ginv(covs) could be used.
covs <- var(rets, na.rm = TRUE)
eigen(covs)$values
giving the following eigenvector which includes 4 near zeros:
[1] 1.147251e-01 4.508339e-03 3.566784e-03 9.437460e-04 6.489510e-04
[6] 4.975564e-04 3.300602e-04 2.840001e-04 2.674243e-04 2.202487e-04
[11] 1.428033e-04 9.985863e-05 9.513909e-05 7.955750e-05 6.892488e-05
[16] 5.715785e-05 4.055359e-05 3.127846e-05 2.710167e-05 6.273551e-06
[21] 6.322894e-19 2.240421e-19 -3.041137e-19 -9.827006e-19

Plotting more than one linear regression line in ggplot

I am trying to plot, using ggplot, a series of scatter plots with regression lines for several datasets. I started with the following dataset, "onepectCO2MEDIAN". The data for this dataset is as follows:
onepctCO2MEDIAN
x y
layer.1 0.000000000 0.0000000
layer.2 0.006794447 4.9002490
layer.3 0.014288058 0.1608000
layer.4 0.022087920 6.6349133
layer.5 0.030797357 -1.2429506
layer.6 0.038451072 1.5643374
layer.7 0.048087904 -2.2659035
layer.8 0.058677729 2.2070045
layer.9 0.069261406 -2.3677001
layer.10 0.080524530 -1.0913506
layer.11 0.092760246 0.4099940
layer.12 0.103789609 -0.1259727
layer.13 0.116953168 -2.4138253
layer.14 0.129253298 7.0890257
layer.15 0.141710050 -0.7593539
layer.16 0.156002052 0.0454416
layer.17 0.170648172 -1.5349683
layer.18 0.185318425 6.5524201
layer.19 0.199463055 -0.8312563
layer.20 0.213513337 -2.5099183
layer.21 0.228839271 0.1365968
layer.22 0.246981293 -1.3719845
layer.23 0.263012767 -0.8712988
layer.24 0.278505564 0.6632584
layer.25 0.293658361 0.7938036
layer.26 0.310747266 3.4880637
layer.27 0.325990349 -4.4612208
layer.28 0.342517540 0.0871734
layer.29 0.362751633 -1.4171578
layer.30 0.380199537 -0.9956508
layer.31 0.394992948 0.3215526
layer.32 0.414373398 3.1403866
layer.33 0.430690214 -0.7376099
layer.34 0.449738145 -2.4860541
layer.35 0.470167458 -3.4235858
layer.36 0.489019871 0.4824748
layer.37 0.507242471 -0.9785386
layer.38 0.524314284 8.5359684
layer.39 0.543750525 5.4844742
layer.40 0.564234197 3.2149367
layer.41 0.583679616 3.9168916
layer.42 0.601459444 4.4907020
layer.43 0.619924664 6.5410410
layer.44 0.639932007 4.8068650
layer.45 0.661347181 8.1510170
layer.46 0.684117317 0.2697413
layer.47 0.704829752 -0.1807501
layer.48 0.725045770 9.7181249
layer.49 0.745165825 1.5406466
layer.50 0.765016139 -1.6476041
layer.51 0.783461511 4.8024603
layer.52 0.806382924 4.0421516
layer.53 0.829241335 9.3756512
layer.54 0.849924415 5.3305050
layer.55 0.871352434 7.5445803
layer.56 0.893632233 6.4679547
layer.57 0.916052133 2.8096065
layer.58 0.938579470 5.3921661
layer.59 0.959907651 7.2043689
layer.60 0.981643587 3.3350806
layer.61 1.004116774 8.8690707
layer.62 1.028363466 1.7861299
layer.63 1.054009140 6.2555038
layer.64 1.072440803 7.6079236
layer.65 1.094457805 7.6871483
layer.66 1.123176277 4.7787764
layer.67 1.149430871 12.7110502
layer.68 1.170912921 -0.7156284
layer.69 1.196743071 1.6490899
layer.70 1.218625903 3.0363024
layer.71 1.241868377 4.2974769
layer.72 1.267941594 1.9543778
layer.73 1.290708780 3.9986964
layer.74 1.313222289 4.5179472
layer.75 1.339045882 0.9337905
layer.76 1.362803459 3.3050770
layer.77 1.384450197 3.5422970
layer.78 1.409720302 5.9973660
layer.79 1.435851157 0.5081869
layer.80 1.455592215 7.9661630
layer.81 1.479495347 9.9460496
layer.82 1.506051958 3.7908372
layer.83 1.525728464 2.5735847
layer.84 1.549362063 10.1404974
layer.85 1.573440671 13.7408304
layer.86 1.600278735 0.9335771
layer.87 1.623879492 9.7588742
layer.88 1.650029302 1.2769395
layer.89 1.672362328 13.4970906
layer.90 1.700221121 10.2087502
layer.91 1.724793375 1.6811275
layer.92 1.751070559 6.1178992
layer.93 1.778022110 -0.1567626
layer.94 1.803022087 3.8237479
layer.95 1.830668867 4.4331468
layer.96 1.855736911 5.9790707
layer.97 1.882615030 11.3104333
layer.98 1.909218490 8.2142607
layer.99 1.938130021 15.3209674
layer.100 1.963727593 5.8178217
layer.101 1.993271947 9.6004907
layer.102 2.022548139 3.4063646
layer.103 2.050679922 4.7375010
layer.104 2.078064442 3.0133019
layer.105 2.104113460 5.5659522
layer.106 2.133597612 12.0346333
layer.107 2.164026260 -0.4028320
layer.108 2.194852829 10.5996780
layer.109 2.224257946 5.4479584
layer.110 2.252194643 4.7052374
layer.111 2.277335048 14.0962019
layer.112 2.304058313 5.7149016
layer.113 2.330930233 3.7780072
layer.114 2.357022762 4.4120620
layer.115 2.386489272 4.1866085
layer.116 2.417503953 6.9078802
layer.117 2.448524356 2.7825739
layer.118 2.478698969 7.6171786
layer.119 2.510175705 10.2410603
layer.120 2.539697886 8.1820711
layer.121 2.567915559 4.8275494
layer.122 2.597463250 19.1624883
layer.123 2.627518773 16.0677109
layer.124 2.658759236 12.5897081
layer.125 2.692401528 9.2907988
layer.126 2.721903205 7.4262502
layer.127 2.753021359 9.3902518
layer.128 2.786313415 12.6193550
layer.129 2.819564104 11.1121040
layer.130 2.850823164 15.7907100
layer.131 2.880394101 10.7425287
layer.132 2.911391258 7.7971430
layer.133 2.942965150 8.8060858
layer.134 2.974468350 17.5606266
layer.135 3.008983612 17.3088605
layer.136 3.040015221 13.4500543
layer.137 3.072668672 14.6377884
layer.138 3.105982423 8.0798552
dput(onepctCO2MEDIAN)
dput(onepctCO2MEDIAN)
structure(list(x = c(0, 0.00679444684647024, 0.014288058038801,
0.0220879195258021, 0.0307973567396402,0.0384510718286037,0.0480879042297602,
0.0586777292191982, 0.0692614056169987, 0.080524530261755,0.0927602462470531,
0.103789608925581, 0.116953168064356, 0.129253298044205, 0.141710050404072,
0.156002052128315, 0.170648172497749, 0.185318425297737, 0.199463054537773,
0.21351333707571, 0.22883927077055, 0.246981292963028, 0.263012766838074,
0.278505563735962, 0.29365836083889, 0.310747265815735, 0.325990349054337,
0.342517539858818, 0.362751632928848, 0.380199536681175, 0.39499294757843,
0.414373397827148, 0.430690214037895, 0.449738144874573, 0.470167458057404,
0.489019870758057, 0.507242470979691, 0.524314284324646, 0.543750524520874,
0.56423419713974, 0.583679616451263, 0.601459443569183, 0.619924664497375,
0.639932006597519, 0.661347180604935, 0.684117317199707, 0.704829752445221,
0.725045770406723, 0.745165824890137, 0.765016138553619, 0.783461511135101,
0.806382924318314, 0.829241335391998, 0.84992441534996, 0.871352434158325,
0.893632233142853, 0.916052132844925, 0.938579469919205, 0.959907650947571,
0.981643587350845, 1.00411677360535, 1.02836346626282, 1.05400913953781,
1.07244080305099, 1.09445780515671, 1.12317627668381, 1.14943087100983,
1.17091292142868, 1.19674307107925, 1.21862590312958, 1.24186837673187,
1.26794159412384, 1.2907087802887, 1.31322228908539, 1.33904588222504,
1.36280345916748, 1.38445019721985, 1.40972030162811, 1.43585115671158,
1.45559221506119, 1.47949534654617, 1.50605195760727, 1.52572846412659,
1.5493620634079, 1.5734406709671, 1.60027873516083, 1.62387949228287,
1.65002930164337, 1.67236232757568, 1.70022112131119, 1.72479337453842,
1.75107055902481, 1.77802211046219, 1.80302208662033, 1.83066886663437,
1.85573691129684, 1.88261502981186, 1.90921849012375, 1.93813002109528,
1.96372759342194, 1.99327194690704, 2.02254813909531, 2.05067992210388,
2.07806444168091, 2.1041134595871, 2.13359761238098, 2.16402626037598,
2.19485282897949, 2.2242579460144, 2.25219464302063, 2.27733504772186,
2.30405831336975, 2.33093023300171, 2.35702276229858, 2.38648927211761,
2.41750395298004, 2.44852435588837, 2.47869896888733, 2.51017570495605,
2.53969788551331, 2.567915558815, 2.59746325016022, 2.62751877307892,
2.65875923633575, 2.69240152835846, 2.72190320491791, 2.75302135944366,
2.78631341457367, 2.8195641040802, 2.85082316398621, 2.88039410114288,
2.91139125823975, 2.94296514987946, 2.97446835041046, 3.00898361206055,
3.04001522064209, 3.07266867160797, 3.10598242282867), y = c(0,
4.90024901723162, 0.160799993152722, 6.63491326258641, -1.24295055804536,
1.56433744259162, -2.26590352245208, 2.20700446463354, -2.36770012911069,
-1.09135061899174, 0.409993989292701, -0.125972681525582, -2.41382533818026,
7.08902570153028, -0.759353880417294, 0.0454415959640926, -1.53496826259972,
6.55242014096194, -0.831256280861552, -2.50991825629084, 0.136596820654013,
-1.37198445498419, -0.871298832596736, 0.663258363762466, 0.793803634291308,
3.48806373666998, -4.46122081238949, 0.0871733966938564, -1.41715777257774,
-0.995650815648318, 0.32155262317503, 3.14038657369241, -0.737609879885404,
-2.48605406511292, -3.423585843908, 0.482474753780281, -0.978538630093809,
8.53596837794201, 5.48447420320695, 3.21493665820644, 3.91689160157513,
4.49070195980797, 6.54104103157039, 4.80686500146557, 8.15101701282067,
0.26974132191657, -0.180750068063062, 9.71812491230244, 1.54064657400204,
-1.64760408795688, 4.80246028991894, 4.04215159914344, 9.37565121768513,
5.33050496938428, 7.54458026088508, 6.46795470819342, 2.80960651433971,
5.39216613235986, 7.20436888038562, 3.3350806460997, 8.86907069895943,
1.78612988613659, 6.25550382050395, 7.60792364896564, 7.68714830528144,
4.77877638957615, 12.7110501777314, -0.715628443181046, 1.64908991824022,
3.03630240714679, 4.29747688442346, 1.95437780501881, 3.99869636910933,
4.51794724689848, 0.933790484492299, 3.30507700050003, 3.5422970157433,
5.99736597322524, 0.508186860060022, 7.96616300581067, 9.94604963036295,
3.79083717222623, 2.57358468532258, 10.1404974171776, 13.7408303595752,
0.933577123801399, 9.75887417074129, 1.27693947132921, 13.4970905965787,
10.2087501765735, 1.68112753028756, 6.1178991508927, -0.156762622680077,
3.82374791691426, 4.43314678736265, 5.97907067167507, 11.3104332518482,
8.21426074201525, 15.320967360602, 5.81782169471483, 9.6004907412354,
3.40636455909704, 4.73750103921864, 3.0133019468806, 5.56595224859066,
12.0346332527215, -0.40283199827104, 10.5996779538754, 5.44795836991128,
4.70523736412729, 14.096201892183, 5.71490161813391, 3.77800720810782,
4.41206200639436, 4.18660847858423, 6.90788020044911, 2.78257393345915,
7.61717857379431, 10.2410602647684, 8.18207106836167, 4.82754943871433,
19.1624882857155, 16.0677109398509, 12.589708067017, 9.29079879799404,
7.42625019725314, 9.39025179806185, 12.6193550331438, 11.1121039747257,
15.7907099734986, 10.7425286789233, 7.79714300307344, 8.80608578166101,
17.5606266346039, 17.3088604929222, 13.4500543478523, 14.6377884248645,
8.07985518296064)), class = "data.frame", row.names = c("layer.1",
"layer.2", "layer.3", "layer.4", "layer.5", "layer.6", "layer.7",
"layer.8", "layer.9", "layer.10", "layer.11", "layer.12", "layer.13",
"layer.14", "layer.15", "layer.16", "layer.17", "layer.18", "layer.19",
"layer.20", "layer.21", "layer.22", "layer.23", "layer.24", "layer.25",
"layer.26", "layer.27", "layer.28", "layer.29", "layer.30", "layer.31",
"layer.32", "layer.33", "layer.34", "layer.35", "layer.36", "layer.37",
"layer.38", "layer.39", "layer.40", "layer.41", "layer.42", "layer.43",
"layer.44", "layer.45", "layer.46", "layer.47", "layer.48", "layer.49",
"layer.50", "layer.51", "layer.52", "layer.53", "layer.54", "layer.55",
"layer.56", "layer.57", "layer.58", "layer.59", "layer.60", "layer.61",
"layer.62", "layer.63", "layer.64", "layer.65", "layer.66", "layer.67",
"layer.68", "layer.69", "layer.70", "layer.71", "layer.72", "layer.73",
"layer.74", "layer.75", "layer.76", "layer.77", "layer.78", "layer.79",
"layer.80", "layer.81", "layer.82", "layer.83", "layer.84", "layer.85",
"layer.86", "layer.87", "layer.88", "layer.89", "layer.90", "layer.91",
"layer.92", "layer.93", "layer.94", "layer.95", "layer.96", "layer.97",
"layer.98", "layer.99", "layer.100", "layer.101", "layer.102",
"layer.103", "layer.104", "layer.105", "layer.106", "layer.107",
"layer.108", "layer.109", "layer.110", "layer.111", "layer.112",
"layer.113", "layer.114", "layer.115", "layer.116", "layer.117",
"layer.118", "layer.119", "layer.120", "layer.121", "layer.122",
"layer.123", "layer.124", "layer.125", "layer.126", "layer.127",
"layer.128", "layer.129", "layer.130", "layer.131", "layer.132",
"layer.133", "layer.134", "layer.135", "layer.136", "layer.137",
"layer.138"))
I started with the following to generate the first regression line and scatter plot:
lm<-ggplot(onepctCO2MEDIAN) +
geom_jitter(aes(RCP1pctCO2cumulativeMedian[1:138], departurea),
colour="blue") + geom_smooth(aes(RCP1pctCO2cumulativeMedian[1:138],
departurea), method=lm)
But I receive this error:
Warning message:
Computation failed in `stat_smooth()`:
'what' must be a function or character string
A blue scatter plot is successfully generated, but the problem is that the regression line does not appear, presumably related to the above warning.
Is there a reason for this? I would appreciate any assistance!
You should be able to get a scatter plot with a regression line by doing the following:
library(tidyverse)
#> Registered S3 methods overwritten by 'ggplot2':
#> method from
#> [.quosures rlang
#> c.quosures rlang
#> print.quosures rlang
onepctCO2MEDIAN <- structure(list(x = c(0, 0.00679444684647024, 0.014288058038801,
0.0220879195258021, 0.0307973567396402,0.0384510718286037,0.0480879042297602,
0.0586777292191982, 0.0692614056169987, 0.080524530261755,0.0927602462470531,
0.103789608925581, 0.116953168064356, 0.129253298044205, 0.141710050404072,
0.156002052128315, 0.170648172497749, 0.185318425297737, 0.199463054537773,
0.21351333707571, 0.22883927077055, 0.246981292963028, 0.263012766838074,
0.278505563735962, 0.29365836083889, 0.310747265815735, 0.325990349054337,
0.342517539858818, 0.362751632928848, 0.380199536681175, 0.39499294757843,
0.414373397827148, 0.430690214037895, 0.449738144874573, 0.470167458057404,
0.489019870758057, 0.507242470979691, 0.524314284324646, 0.543750524520874,
0.56423419713974, 0.583679616451263, 0.601459443569183, 0.619924664497375,
0.639932006597519, 0.661347180604935, 0.684117317199707, 0.704829752445221,
0.725045770406723, 0.745165824890137, 0.765016138553619, 0.783461511135101,
0.806382924318314, 0.829241335391998, 0.84992441534996, 0.871352434158325,
0.893632233142853, 0.916052132844925, 0.938579469919205, 0.959907650947571,
0.981643587350845, 1.00411677360535, 1.02836346626282, 1.05400913953781,
1.07244080305099, 1.09445780515671, 1.12317627668381, 1.14943087100983,
1.17091292142868, 1.19674307107925, 1.21862590312958, 1.24186837673187,
1.26794159412384, 1.2907087802887, 1.31322228908539, 1.33904588222504,
1.36280345916748, 1.38445019721985, 1.40972030162811, 1.43585115671158,
1.45559221506119, 1.47949534654617, 1.50605195760727, 1.52572846412659,
1.5493620634079, 1.5734406709671, 1.60027873516083, 1.62387949228287,
1.65002930164337, 1.67236232757568, 1.70022112131119, 1.72479337453842,
1.75107055902481, 1.77802211046219, 1.80302208662033, 1.83066886663437,
1.85573691129684, 1.88261502981186, 1.90921849012375, 1.93813002109528,
1.96372759342194, 1.99327194690704, 2.02254813909531, 2.05067992210388,
2.07806444168091, 2.1041134595871, 2.13359761238098, 2.16402626037598,
2.19485282897949, 2.2242579460144, 2.25219464302063, 2.27733504772186,
2.30405831336975, 2.33093023300171, 2.35702276229858, 2.38648927211761,
2.41750395298004, 2.44852435588837, 2.47869896888733, 2.51017570495605,
2.53969788551331, 2.567915558815, 2.59746325016022, 2.62751877307892,
2.65875923633575, 2.69240152835846, 2.72190320491791, 2.75302135944366,
2.78631341457367, 2.8195641040802, 2.85082316398621, 2.88039410114288,
2.91139125823975, 2.94296514987946, 2.97446835041046, 3.00898361206055,
3.04001522064209, 3.07266867160797, 3.10598242282867),
y = c(0,
4.90024901723162, 0.160799993152722, 6.63491326258641, -1.24295055804536,
1.56433744259162, -2.26590352245208, 2.20700446463354, -2.36770012911069,
-1.09135061899174, 0.409993989292701, -0.125972681525582, -2.41382533818026,
7.08902570153028, -0.759353880417294, 0.0454415959640926, -1.53496826259972,
6.55242014096194, -0.831256280861552, -2.50991825629084, 0.136596820654013,
-1.37198445498419, -0.871298832596736, 0.663258363762466, 0.793803634291308,
3.48806373666998, -4.46122081238949, 0.0871733966938564, -1.41715777257774,
-0.995650815648318, 0.32155262317503, 3.14038657369241, -0.737609879885404,
-2.48605406511292, -3.423585843908, 0.482474753780281, -0.978538630093809,
8.53596837794201, 5.48447420320695, 3.21493665820644, 3.91689160157513,
4.49070195980797, 6.54104103157039, 4.80686500146557, 8.15101701282067,
0.26974132191657, -0.180750068063062, 9.71812491230244, 1.54064657400204,
-1.64760408795688, 4.80246028991894, 4.04215159914344, 9.37565121768513,
5.33050496938428, 7.54458026088508, 6.46795470819342, 2.80960651433971,
5.39216613235986, 7.20436888038562, 3.3350806460997, 8.86907069895943,
1.78612988613659, 6.25550382050395, 7.60792364896564, 7.68714830528144,
4.77877638957615, 12.7110501777314, -0.715628443181046, 1.64908991824022,
3.03630240714679, 4.29747688442346, 1.95437780501881, 3.99869636910933,
4.51794724689848, 0.933790484492299, 3.30507700050003, 3.5422970157433,
5.99736597322524, 0.508186860060022, 7.96616300581067, 9.94604963036295,
3.79083717222623, 2.57358468532258, 10.1404974171776, 13.7408303595752,
0.933577123801399, 9.75887417074129, 1.27693947132921, 13.4970905965787,
10.2087501765735, 1.68112753028756, 6.1178991508927, -0.156762622680077,
3.82374791691426, 4.43314678736265, 5.97907067167507, 11.3104332518482,
8.21426074201525, 15.320967360602, 5.81782169471483, 9.6004907412354,
3.40636455909704, 4.73750103921864, 3.0133019468806, 5.56595224859066,
12.0346332527215, -0.40283199827104, 10.5996779538754, 5.44795836991128,
4.70523736412729, 14.096201892183, 5.71490161813391, 3.77800720810782,
4.41206200639436, 4.18660847858423, 6.90788020044911, 2.78257393345915,
7.61717857379431, 10.2410602647684, 8.18207106836167, 4.82754943871433,
19.1624882857155, 16.0677109398509, 12.589708067017, 9.29079879799404,
7.42625019725314, 9.39025179806185, 12.6193550331438, 11.1121039747257,
15.7907099734986, 10.7425286789233, 7.79714300307344, 8.80608578166101,
17.5606266346039, 17.3088604929222, 13.4500543478523, 14.6377884248645,
8.07985518296064)),
class = "data.frame", row.names = c("layer.1",
"layer.2", "layer.3", "layer.4", "layer.5", "layer.6", "layer.7",
"layer.8", "layer.9", "layer.10", "layer.11", "layer.12", "layer.13",
"layer.14", "layer.15", "layer.16", "layer.17", "layer.18", "layer.19",
"layer.20", "layer.21", "layer.22", "layer.23", "layer.24", "layer.25",
"layer.26", "layer.27", "layer.28", "layer.29", "layer.30", "layer.31",
"layer.32", "layer.33", "layer.34", "layer.35", "layer.36", "layer.37",
"layer.38", "layer.39", "layer.40", "layer.41", "layer.42", "layer.43",
"layer.44", "layer.45", "layer.46", "layer.47", "layer.48", "layer.49",
"layer.50", "layer.51", "layer.52", "layer.53", "layer.54", "layer.55",
"layer.56", "layer.57", "layer.58", "layer.59", "layer.60", "layer.61",
"layer.62", "layer.63", "layer.64", "layer.65", "layer.66", "layer.67",
"layer.68", "layer.69", "layer.70", "layer.71", "layer.72", "layer.73",
"layer.74", "layer.75", "layer.76", "layer.77", "layer.78", "layer.79",
"layer.80", "layer.81", "layer.82", "layer.83", "layer.84", "layer.85",
"layer.86", "layer.87", "layer.88", "layer.89", "layer.90", "layer.91",
"layer.92", "layer.93", "layer.94", "layer.95", "layer.96", "layer.97",
"layer.98", "layer.99", "layer.100", "layer.101", "layer.102",
"layer.103", "layer.104", "layer.105", "layer.106", "layer.107",
"layer.108", "layer.109", "layer.110", "layer.111", "layer.112",
"layer.113", "layer.114", "layer.115", "layer.116", "layer.117",
"layer.118", "layer.119", "layer.120", "layer.121", "layer.122",
"layer.123", "layer.124", "layer.125", "layer.126", "layer.127",
"layer.128", "layer.129", "layer.130", "layer.131", "layer.132",
"layer.133", "layer.134", "layer.135", "layer.136", "layer.137",
"layer.138"))
# Create scatterplot from dataframe "onepctCO2MEDIAN" with "x" and "y" variables and add "lm"
onepctCO2MEDIAN %>%
ggplot(aes(x = x, y = y)) +
geom_point() +
xlab("x") +
ylab("y") +
geom_smooth(method = "lm")
Created on 2019-06-07 by the reprex package (v0.3.0)

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

Error when using cluster package to compute euclidean distances

I have been working on a text mining project. I have performed some LDA topic modelling and now I have my topic probabilities. I would like to use the cluster package so that I can get the euclidean distances between documents so I can create a network graph, but I keep on getting an error. Any recommendation for good visualisation techniques would also be warmly welcomed :)
library(cluster)
FundDist <- as.matrix(daisy(EUTopicNetworks, metric = "euclidean", stand = TRUE))
Error in daisy(EUTopicNetworks, metric = "euclidean", stand = TRUE) : invalid type character for column numbers 1
In addition: Warning messages:
1: In data.matrix(x) : NAs introduced by coercion
2: In daisy(EUTopicNetworks, metric = "euclidean", stand = TRUE) :
with mixed variables, metric "gower" is used automatically
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
I have never uploaded reproducible data on this website using the dput() function before. So I hope I have done this correct. I have copied and pasted the output below. Thank you for taking the time to read my problem.
EUTopicNetworks <- structure(list(Filename = c("AT_Burenland_2007.txt", "AT21_Kaernten_07.txt",
"AT12_LowerAustria_07_13.txt", "AT_Nat_2007.txt", "AT34_Salzburg_07.txt",
"AT22_Steiermark_07.txt", "AT36_Tirol_07.txt", "UpperAustria2007.txt",
"AT13_Vienna_07.txt", "vorarlberg2007.txt", "AT_Austria_1.txt",
"AT11_Burgenland_1", "lowe austria 2014.txt", "AT13_Vienna2_14.txt",
"AT21_Kaernten_14.txt", "AT22_Steiermark_14.txt", "AT31_UpperAustria_14.txt",
"AT35_Salzburg_14.txt", "AT36_Tirol_14.txt", "AT37_Vorarlberg_14.txt",
"abbruzzo2007-2013.txt", "calabria2007-2013.txt", "campania2007-2013.txt",
"emiliaromagna2007-2013.txt", "sicily2007.txtt", "friuli2007-2013.txt",
"lazio2007-2013.txt", "liguria2007.txt", "lombardy2007-2013.txt",
"piemonte2007-2013.txt", "puglia2007-2013.txt", "sardinia2007-2013.txt",
"Bolzano_07.txt", "umbria 2007-2013.txt", "valledaosta 2007-2013.txt",
"tuscany2007.txt", "VENETO2007-2013.txt", "abruzzo2014-2020.txt",
"basilicata2014-2020.txt", "calabria2014-2020.txt", "campania2014-2020.txt",
"emiliaromagna2014-2020.txt", "sicily2014.txt", "friuli2014-2020.txt",
"lazio2014.txt", "liguria2014.txt", "lombardia2014-2020.txt",
"piemonte2014-2020.txt", "puglia_14.txt", "sardinia2014.txt",
"Bolzano_14.txt", "umbria2014.txt", "valledaosta 2014-2020.txt",
"tuscany2014.txt", "molise_14.txt", "molise_07.txt", "trento2007.txt",
"trento2014.txt", "ITALIANSTRATEGICPLAN2007-2013.txt", "italyinnovationstrategy2014-2020.txt",
"veneto2014-2020.txt", "aquitanie2014-2020.txt", "aquitanie2007.txt",
"auvergne2014-2020.txt", "auvergne_07.txt", "bretagne2014-2020.txt",
"bretagne_07.txt", "centre2014-2020.txt", "centre2007.txt", "champagne-ardenne 2007.txt",
"champagne-ardenne 2014.txt", "PICARDIE2007.txt", "picardie2014.txt",
"bassenormandie 2007.txt", "bassenormandie 2014.txt", "bourgogne2014.txt",
"bourgogne_07.txt", "midi-pyrenees2007.txt", "midipyrennes14.txt",
"franche-comte2014-2020.txt", "franche-comte_2007.txt", "hautenormandie2007.txt",
"hautenormandie2014-2020.txt", "limousine2014-2020.txt", "limousine2007.txt",
"loire2007.txt", "loire2014-2020.txt", "lorraine2014-2020.txt",
"lorraine2007.txt", "nordpasdecalais2007.txt", "nordpasdecalais2014-2020.txt",
"rhonealpes2014-2020.txt", "rhone-alpes2007.txt", "poitou-charenter2007.txt",
"poituou-charentes2014.txt", "corse2007.txt", "corsica.txt",
"bretagne_07.txt", "bretagne2014-2020.txt", "Baden-Wu_07.txt",
"Baden-wu14.txt", "bavaria2007.txt", "BAVARIA_14.txt", "BERLIN2014-2020.txt",
"Berlin_07.txt", "bradenburgh2014.txt", "Bradenburgh2007.txt",
"bremen2007.txt", "bremen2014.txt", "hamburg_07.txt", "HAMBURGO2014-2020.txt",
"Hessen_07.txt", "Hessian1.txt", "LowerSaxony2_07.txt", "LOWERSAXONY2014-2020.txt",
"Mecklenburg_07.txt", "MECKPOMM2014-2020.txt", "rheinland2014-2020.txt",
"RhinelanPlatz_07.txt", "saarland2014-2020.txt", "saarland_07.txt",
"sachsen-anhalt2014-2020.txt", "sachsen-anhelt2007.txt", "saxony_07.txt",
"saxony_14.txt", "Schleswig-Holstein2020.txt", "Schleswig-Holstein_07.txt",
"thuringia2007.txt", "THURINGIA2014-2020.txt", "Andalucia_2007-2013.txt",
"Andalusia_14.txt", "Aragon_14.txt", "Aragon_2007.txt", "Asturias_2007.txt",
"ES12_Asturias.txt", "Baleares_2007.txt", "Balears_14.txt", "Canarias_07.txt",
"Canaries_14.txt", "Cantabria_2007.txt", "ES13_Cantabria_14.txt",
"Castillala_Mancha_2007.txt", "ES42_Castilla-la_mancha.txt",
"CastillayLeon_dic_2007.txt", "ES41_Castilla-Leon.txt", "ES51_Catalonia_14.txt",
"catalonia2007.txt", "Madrid_2007-13.txt", "Madrid_14.txt", "Murcia_14.txt",
"murcia2007.txt", "Valencia_14.txt", "Valenciana_2007.txt", "laRioja2007.txt",
"CombiEngland_07.txt", "EastWales_07.txt", "NorthernIreland_07.txt",
"Scotland_07.txt", "WestWales_07.txt", "EastWales_14.txt", "England_14.txt",
"Northern_Ireland14.txt", "Scotland14.txt", "Westwales_14.txt",
"malta2007-2013.2.txt", "malta2014-2020.txt2.txt"), Funds = c(0.028649302,
0.036198106, 0.041060412, 0.036543709, 0.047044295, 0.01659907,
0.019221094, 0.056763265, 0.052615278, 0.045216842, 0.048176521,
0.038976137, 0.027341846, 0.037721688, 0.049252945, 0.05918185,
0.05440539, 0.017412537, 0.029307636, 0.022385126, 0.019737738,
0.027626844, 0.0334503, 0.043976555, 0.042856083, 0.021046234,
0.018061427, 0.014983543, 0.067145641, 0.019741648, 0.019018285,
0.030614714, 0.019666862, 0.028158874, 0.026009936, 0.019330949,
0.023088856, 0.044273539, 0.021168401, 0.017627883, 0.030486684,
0.017509486, 0.034035728, 0.034106673, 0.043486846, 0.029087254,
0.050564915, 0.047219925, 0.051437475, 0.029694445, 0.008588781,
0.045469371, 0.060967658, 0.049260664, 0.015106536, 0.026186649,
0.023254401, 0.053579943, 0.031056644, 0.045125396, 0.057680642,
0.01125217, 0.042532521, 0.041545015, 0.047940862, 0.036641552,
0.072252939, 0.035679102, 0.067488953, 0.008492444, 0.021052205,
0.020152732, 0.040564092, 0.02921307, 0.018565646, 0.022775302,
0.011711217, 0.019967731, 0.00877454, 0.022250866, 0.003696986,
0.011277284, 0.007740289, 0.02790784, 0.008134596, 0.014931457,
0.03269353, 0.041386999, 0.066164327, 0.011440048, 0.006215758,
0.010688796, 0.003811851, 0.003303556, 0.023094521, 0.010550119,
0.018023822, 0.022757839, 0.017667203, 0.02073341, 0.013537221,
0.011950717, 0.009010298, 0.019796088, 0.011314152, 0.01098032,
0.008832217, 0.040330019, 0.005822583, 0.006599734, 0.016338338,
0.013906508, 0.010973094, 0.010448791, 0.003723683, 0.013769165,
0.007583811, 0.009724543, 0.00237987, 0.005005899, 0.005048481,
0.013000829, 0.012671508, 0.003054379, 0.03508621, 0.012981055,
0.021982606, 0.009448894, 0.014883524, 0.018772709, 0.006068872,
0.018122102, 0.020449118, 0.015102835, 0.005449833, 0.011014679,
0.016602374, 0.006482356, 0.009969209, 0.002646448, 0.01205523,
0.04659564, 0.010866707, 0.0144986, 0.046946229, 0.028629168,
0.034634807, 0.059078927, 0.002919951, 0.016168915, 0.024403654,
0.09171777, 0.009978063, 0.015196456, 0.015174811, 0.047399696,
0.015303701, 0.011753077, 0.014862118, 0.01487099, 0.011742448,
0.018346786, 0.010785336, 0.010421162, 0.013791872, 0.026389358
), Biotech = c(0.024814541, 0.005668351, 0.017716491, 0.00853945,
0.015916015, 0.03888657, 0.001333459, 0.017368849, 0.023781704,
0.051278428, 0.005484117, 0.021759003, 0.027973849, 0.002774256,
0.005744201, 0.004244159, 0.00468969, 0.000581776, 0.022734494,
0.03445351, 0.000800523, 0.000362683, 0.026945766, 0.006823146,
0.005847249, 0.000630851, 0.020794353, 0.035979974, 0.006165474,
0.027793267, 0.00504312, 0.018927097, 0.000760576, 0.012289583,
0.002109001, 0.000442817, 0.000594334, 0.00037428, 0.06596126,
0.027988907, 0.019067461, 0.024872467, 0.015379713, 0.015295277,
9.36e-05, 0.000117979, 4e-05, 0.031220784, 0.001357913, 0.040951957,
0.000438858, 0.038880733, 0.00115553, 0.041152387, 0.042576251,
0.002254845, 0.022345729, 0.002596388, 0.022562024, 0.000243528,
0.000885187, 0.013339204, 0.001418329, 0.028089687, 0.002057198,
0.000244579, 0.000140129, 0.051721762, 0.014989271, 0.001673642,
0.04500578, 0.001615416, 0.00010688, 8.18e-05, 0.000526549, 0.024849247,
0.032961749, 0.033875354, 0.032145136, 0.012619383, 0.003522134,
0.012225185, 0.043464039, 0.077400519, 0.056308327, 0.020638077,
0.049992043, 0.038864222, 0.039459316, 0.034937031, 0.037406742,
0.029987413, 0.002413193, 0.000584526, 0.004584848, 0.012491496,
0.031710331, 0.017858395, 0.030812232, 0.003435739, 0.02648106,
0.006927007, 0.030785802, 0.044329986, 0.009838859, 0.002951219,
0.030722621, 0.020511401, 0.013623405, 0.081263322, 0.029623712,
0.003790876, 0.00335598, 0.018842609, 0.008430911, 0.032611226,
0.057455638, 0.004304486, 0.015733474, 0.043981231, 7.95e-05,
0.004054158, 0.045173701, 0.016378658, 0.015906368, 2.92e-05,
0.00057313, 0.00079682, 0.013209159, 0.039911915, 0.000237856,
0.022373161, 0.015821272, 0.026750309, 0.048698356, 0.041430357,
0.00287091, 0.007965338, 0.034481633, 0.001543219, 0.022152119,
0.041801127, 0.017463336, 0.038010604, 0.050393079, 0.045031199,
0.043613378, 0.037411148, 0.00186188, 0.018962051, 0.043254408,
0.018666636, 0.027696462, 0.024293257, 0.062711642, 0.000519461,
0.001056595, 0.031300324, 0.024742217, 0.024718682, 0.000780182,
0.01862668, 0.000973041, 0.000542227, 0.001011475, 0.011077226
), Transfers = c(0.00473547, 0.00038783, 0.000424567, 0.000695775,
0.000135175, 0.010334213, 0.000106781, 0.003008423, 0.000608193,
0.010326284, 0.000934925, 0.031277279, 0.00572826, 0.000260722,
0.001021529, 0.000154104, 0.000220061, 4.32e-05, 0.018335222,
0.013011634, 2.49e-05, 4.83e-05, 0.021935677, 0.000390414, 0.000130749,
3.77e-05, 0.009460382, 0.146681735, 7.44e-05, 0.082389135, 0.000592343,
0.000562132, 1.53e-05, 0.020403948, 1.31e-05, 2.46e-05, 5.51e-05,
0.000321357, 0.037377138, 0.006516009, 0.022055996, 0.041838049,
0.002549792, 0.00271147, 8.55e-05, 0.001550897, 0.001094715,
0.002059784, 2.73e-05, 0.012813067, 9.84e-06, 0.009924993, 8.74e-05,
0.004619721, 0.013069859, 2.14e-05, 0.053722696, 5.79e-05, 0.006753522,
1.18e-05, 0.005116721, 0.000108002, 2.73e-05, 0.003596542, 2.79e-05,
0.00438903, 8.31e-05, 0.026310482, 0.001005592, 0.000428282,
0.049529581, 1.93e-05, 8.57e-05, 0.001610554, 9.92e-06, 0.094923027,
0.031919217, 0.13955002, 0.083229087, 0.000284159, 0.000267466,
0.000349366, 0.056697448, 0.049064161, 0.075636951, 0.004204928,
0.006115066, 0.007264789, 0.002044115, 0.043477142, 0.046506897,
0.082070827, 0.00035585, 0.010126049, 0.000178782, 0.000133394,
0.019258021, 9.19e-05, 0.069771158, 0.164961859, 0.030302868,
0.008376654, 0.095394069, 0.069931231, 0.000553351, 0.000544636,
0.095332857, 0.001748097, 0.000288915, 0.049584358, 0.095331287,
0.000598831, 0.001574565, 0.124263691, 3.34e-05, 0.107925558,
0.087354139, 0.000618826, 0.000110399, 0.035831715, 5.52e-06,
0.003000538, 0.076722556, 0.001625612, 0.00057855, 2.15e-05,
6.78e-05, 0.000268523, 0.000567245, 0.04113056, 1.71e-05, 0.03401376,
0.001848523, 0.029357767, 0.078771496, 0.05552954, 0.068487283,
0.001617493, 0.045003856, 0.000170027, 0.102169304, 0.033286348,
0.000645582, 0.123061518, 0.024437451, 0.002628661, 0.013120533,
0.002000205, 0.000545963, 0.103891281, 0.01547252, 0.004918401,
0.032767954, 0.084638687, 0.093356166, 0.000156201, 0.000752217,
0.109659324, 0.208642497, 0.208474925, 0.000404265, 0.078084401,
0.000538784, 0.012066067, 0.018067282, 0.000205862), Collab = c(0.030001488,
0.036707564, 0.01458121, 0.026231048, 0.018525526, 0.011553297,
0.058634057, 0.001686141, 0.001348074, 0.006757227, 0.013508918,
0.003715637, 0.002921306, 0.009278328, 0.004626478, 0.002879119,
0.055770088, 0.095661212, 0.017193222, 0.004260887, 0.0994825,
0.094794299, 0.00236101, 0.05708391, 0.070789976, 0.093534164,
0.001109712, 0.009766358, 0.033402635, 0.011669702, 0.06682796,
0.001608723, 0.076258585, 0.0177607, 0.081032098, 0.094412392,
0.105163053, 0.000130001, 0.000308904, 0.000673957, 0.000108183,
0.006185235, 0.001417778, 0.001392482, 0.001763266, 4.19e-05,
0.000316372, 0.000538187, 0.057255911, 0.000888558, 0.117687659,
0.002003037, 0.068194122, 0.000653657, 0.000152612, 0.089555908,
0.002829031, 0.032391752, 0.000114824, 0.001213285, 0.000386851,
0.015705495, 0.049863754, 0.000186015, 0.036288112, 0.000121075,
0.001514642, 0.00150885, 0.000594681, 0.139375952, 0.002323917,
0.075647519, 0.002870689, 3.77e-05, 0.077144908, 0.026437255,
0.000115174, 0.00227099, 0.004700389, 0.041492391, 0.122675327,
0.020817113, 6.89e-05, 0.000303617, 0.000137477, 0.001432608,
0.000184365, 0.001050974, 0.000709209, 0.000270104, 0.000303001,
0.018320147, 0.099247105, 0.082998488, 0.000888759, 0.016183068,
0.006294048, 0.002853816, 0.019514895, 0.038458183, 0.002923949,
0.106293548, 0.011739459, 0.000128574, 0.007004556, 0.114129525,
0.012154148, 0.00942754, 0.009594396, 1.79e-05, 0.003734627,
8.05e-06, 0.119908919, 0.018081544, 0.075305864, 0.008538072,
0.000172614, 0.011539718, 0.001156176, 2.3e-05, 0.06492041, 0.12754611,
0.00024379, 0.006267908, 0.00306844, 0.001193837, 0.013286424,
0.113241894, 0.00550093, 0.000513184, 0.164987722, 0.008430982,
0.01127053, 0.00073653, 0.000330426, 0.002238095, 0.104762755,
0.010050252, 0.000469937, 0.145991698, 0.016278919, 0.000640692,
0.005282822, 0.005445685, 0.00014593, 0.000589578, 0.003085291,
0.003763146, 0.118843056, 0.019891671, 0.007112815, 0.004553507,
0.014161345, 0.011043344, 1.65e-05, 0.05419503, 0.107074967,
0.01952576, 0.015831838, 0.015618949, 0.133629759, 0.016718132,
0.120940954, 0.072855599, 0.066799617, 0.006925232)), .Names = c("Filename",
"Funds", "Biotech", "Transfers", "Collab"), class = "data.frame", row.names = c(NA,
-166L))
As #Cath mentioned, your problem is with the column of text. Removing this works:
EUTopicNetworks2 <- EUTopicNetworks[,-1]
class(EUTopicNetworks2)
library(cluster)
FundDist <- as.matrix(daisy(EUTopicNetworks2, metric = "euclidean", stand = TRUE))
By running this code I was able to answer the question I posed in one of the comments
row.names(EUTopicNetworks) <- EUTopicNetworks[,1]
EUTopicNetworks <- EUTopicNetworks[,-1]
library(cluster)
FundDist <- as.matrix(daisy(EUTopicNetworks, metric = "euclidean", stand = TRUE))

How to plot the forecasted values against actual values observed later in R?

We used the R library forecast to make predictions for the next 24 hours. We have the following:
fore_cast=forecast.tbats(model,h=24,level=90)
fore_cast
Point Forecast Lo 90 Hi 90
5.380952 6270.778 5389.089 7296.643
5.386905 5458.096 4557.375 6536.743
5.392857 5219.995 4248.967 6412.814
5.398810 5187.102 4126.390 6520.328
Now we have 2 problems:
We need 'time' (in hour e.g. 01,23,19 etc) instead of 'point'.
We wish to plot the trendline against time showing the actual observed
values against these predicted values. We have loaded actual observed
values from a CSV file.
We tried:
actual_data = read.csv('actualdata.csv')
plot(actual_data,fore_cast)
Doesn't work, and using plot(actual_data) just shows some points in a straight line instead of curved trendline.
EDIT:
Sample output of fore_cast from dput:
structure(list(model = structure(list(lambda = 0.000438881055939422,
alpha = 0.65694875480321, beta = -0.0983972877836753, damping.parameter = 0.800419363290521,
gamma.one.values = c(-0.00150031474145603, -0.00124696854910294
), gamma.two.values = c(0.0023600487982342, -0.002465549595849
), ar.coefficients = NULL, ma.coefficients = NULL, likelihood = 13202.294346586,
optim.return.code = 0L, variance = 0.00855092137349485, AIC = 13258.294346586,
parameters = structure(list(vect = c(0.000438881055939422,
0.65694875480321, 0.800419363290521, -0.0983972877836753,
-0.00150031474145603, -0.00124696854910294, 0.0023600487982342,
-0.002465549595849), control = structure(list(use.beta = TRUE,
use.box.cox = TRUE, use.damping = TRUE, length.gamma = 4L,
p = 0, q = 0), .Names = c("use.beta", "use.box.cox",
"use.damping", "length.gamma", "p", "q"))), .Names = c("vect",
"control")), seed.states = structure(c(7.44188559667267,
0.00357069100887873, -0.0664300680553579, 0.0229067500159256,
0.00460111570469819, -0.00772324725408007, -0.000610110386029883,
0.00568378752162509, -0.0084050648066819, -0.0324093004247092,
-0.000720936399990958, -0.00705790547321605, -0.00738992950838566,
0.00180424326179638, -0.00107745502434416, 0.00242014705705761,
-0.01824679745657, 0.0123019701003545, -0.0245935735677402,
0.0181321397860132), .Dim = c(20L, 1L)), fitted.values = structure(c(1598.57443298879,
1435.74973092922, 1397.92464316794, 1296.90202189518, 1440.3201303663,
1544.11695101118, 1777.97079874181, 1766.50571671645, 1925.27360388028,
1863.26963233038, 1773.08363764691, 1887.26580055295, 1887.48006609474,
1841.66200850472, 1991.90290660363, 2233.04775631848, 2081.30246965768,
1872.12639817609, 1899.38583561568, 2213.43437455052, 2214.00832820531,
1745.36311914995, 1678.67975050944, 1502.35472259274, 1512.27350460399,
1456.14165844166, 1464.3803467642, 1517.99443293857, 1484.54280422369,
1382.37041287489, 1452.43700910726, 1545.16934543365, 1440.50974319508,
1475.59742668699, 1544.88546424501, 1790.95280713647, 1916.4267023671,
1928.72804180587, 1819.15839770808, 1916.43079357329, 1836.80043977753,
1720.25638746452, 1730.03629161412, 1614.6048115754, 1599.23641723244,
1635.86950932066, 1543.46360784778, 1641.35066985679, 1608.60556151299,
1651.47649465456, 1475.15006990464, 1403.67294742438, 1507.58932406857,
1666.3170708439, 1696.06132797576, 1543.32187293056, 1704.58043626911,
1914.72424191575, 2109.33624862625, 2092.98934458578, 2222.13355258602,
2084.68677709368, 1962.9230489947, 2045.61547393981, 2140.30565941261,
2097.46130996426, 2126.07936955385, 2226.18935508502, 2269.54492801286,
2300.37314952852, 2398.48786829541, 2303.31270702723, 2332.74139979969,
2146.51487558643, 2101.27480789243, 2111.61910899422, 2053.57840714969,
2046.56606362537, 2073.82870990658, 2094.88831798868, 2334.85185938782,
2541.72156227893, 2502.36031483721, 2398.12240784327, 2266.35832277135,
2151.05248890962, 2266.88803633019, 2366.19453856405, 2399.97570044332,
2341.74959623409, 2144.33465155869, 2102.91952061083, 2214.48622101851,
2179.48115699957, 2288.28092735955, 2224.55218736155, 2195.1506809087,
2163.94619334319, 2161.41843642149, 2134.75060670667, 2138.77895768654,
2142.84680080931, 2258.55072549978, 2297.90237035988, 2314.94197015208,
2300.99928929609, 2277.39754662665, 2291.06980363364, 2487.04257346235,
2381.05768214413, 2509.40078456481, 2657.61336243367, 2528.65026804303,
2434.2722174014, 2366.04811963942, 2270.6647135766, 2231.33965004538,
2376.51043520344, 2249.42861599343, 2193.98771109322, 2252.12327312365,
2210.76969838623, 2180.50451255189, 2221.92898123682, 2537.84678083006,
2329.57350097532, 2252.82349908982, 2143.92033677754, 2092.3142840022,
2084.70304624685, 2111.18929138546, 2160.05383108999, 2280.94409931504,
2118.22029344747, 2214.65738250204, 2269.05911898631, 2084.26658709038,
2016.04764576402, 2095.57091797435, 2161.07354463394, 2427.77607700887,
2333.91103594967, 2234.23838054763, 2250.71557301013, 2186.97925802073,
2129.51096829218, 2115.40228652934, 2094.89231085691, 2086.41044567131,
2180.94542608489, 2105.38187642016, 2459.45788915933, 2292.36325639374,
2410.75372754831, 2375.56640249604, 2491.11938114866, 2470.51372278037,
2464.95765202085, 2600.85929020727, 2709.48518695182, 2779.77558137814,
2518.29927341458, 2344.06621605191, 2391.56719713269, 2368.68842788795,
2199.93530349068, 2113.92970206565, 2458.96718445444, 3121.97852988865,
2559.40932439262, 2331.12829078836, 2238.54586985577, 2241.91440620202,
2225.29804576634, 2154.14147781021, 2060.57980596908, 2037.30100544426,
2215.93410789353, 2364.42668160056, 2518.72871618042, 2537.34279365294,
2473.76096855791, 2623.63387707374, 2589.08335304697, 2577.0563838788,
2349.53279218826, 2305.52193868551, 2232.63712180453, 2167.50003597208,
2320.23187534213, 2281.86365949586, 2281.21119271599, 2323.2014703372,
2185.94404743238, 2140.21863271207, 2011.67723856012, 1966.52063119589,
2002.67344212857, 1952.41101080662, 1988.37461163105, 2126.75137749373,
2239.14722292367, 2320.98046489603, 2444.91847853015, 2431.69548763034,
2514.73820659393, 2505.85249387343, 2888.19773974179, 2853.20690693738,
2502.20865871069, 2524.56894781003, 2659.52271740553, 2615.9025930681,
2923.69327019152, 2754.76074569658, 2784.59488335761, 2874.24378479002,
2683.41908597168, 2733.83011888159, 2774.1325162997, 2906.41593326865,
2726.06821502751, 2460.21579967528, 2450.8035097605, 2547.39389733175,
2625.60323572861, 2827.94083526683, 2971.92012845614, 3042.90981987278,
2835.00811374845, 2846.98066660519, 2871.21876763166, 2901.99696373824,
2627.47532996657, 2583.75084300313, 2602.68041642846, 2632.8054092953,
2667.85374690972, 2639.10586730146, 2466.95799545022, 2381.06823502402,
2531.32611053776, 2407.14812148706, 2342.75701798463, 2401.73791085847,
2365.50645844524, 2404.50408575777, 2452.57343738519, 2613.15332739214,
2665.50965844576, 2723.8237337447, 2915.09266385617, 2890.17498445896,
2853.6278331055, 2868.1228183545, 2917.07803535669, 2876.59409770233,
2577.82035337979, 2581.91435020803, 2520.20342021937, 2603.37973251208,
2536.03988578365, 2510.83398648802, 2472.80606784857, 2425.51212342113,
2442.02863541673, 2465.73405821711, 2384.42988766816, 2555.51500549788,
2737.77091706275, 2425.00224845814, 2460.17325671183, 2639.16650619329,
2816.37024420397, 2755.69999167982, 2802.64991688288, 2685.12803367301,
2521.77568128564, 2500.99980614696, 2620.41659854805, 2529.25134423133,
2590.14804885984, 2318.80485234464, 2341.88940012276, 2460.21008281205,
2513.70688167177, 2437.71670675479, 2383.29782281743, 2499.36244454453,
2472.98602901478, 2491.10649022417, 2350.1405559119, 2362.78308814045,
2431.3911847573, 2321.15216823049, 2355.74203614213, 2429.60523843166,
2355.61947983433, 2346.3751018515, 2453.82214513707, 2542.98125962684,
2342.43364707529, 2302.17741211575, 2388.93541944219, 2435.41878657221, ....
Sample output from dput for actual observed values:
structure(list(index12 = c(6297.416944, 5406.865556, 4718.355556,
5304.729167, 4968.014722, 5081.130833, 5544.955, 4655.009444,
4269.023056, 4346.588333, 4511.455833, 5102.57, 4818.673333,
4862.343056, 4785.176667, 5385.005278, 6469.080833, 7166.025278,
7010.708333, 511.114167)), .Names = "index12", class = "data.frame", row.names = c(NA,
-20L))
The value of Point is unusual in spite of hour unit data. I think you failed to make a model.
Here is my example:
actual_data <- structure(list(index12 = c(6297.416944, 5406.865556, 4718.355556,
5304.729167, 4968.014722, 5081.130833, 5544.955, 4655.009444,
4269.023056, 4346.588333, 4511.455833, 5102.57, 4818.673333,
4862.343056, 4785.176667, 5385.005278, 6469.080833, 7166.025278,
7010.708333, 511.114167)),
.Names = "index12", class = "data.frame", row.names = c(NA, -20L))
# I suppose that actual_data was taken per hour.
num_actual <- as.numeric(actual_data[,1])
model <- bats(num_actual)
fore_cast <- forecast(model, h=24, level=90)
fore_cast # Point is from 21 to 44 because of length(actual_data)=20 and demanding predictions for the next 24 hours
# Point Forecast Lo 90 Hi 90
# 21 5063.207 2902.187 7224.226
# 22 5108.114 2946.988 7269.241
# :
# 44 5108.114 2944.629 7271.600
# plot() has forecast method. It draws actual_data and prediction, and paints Lo90-Hi90.
plot(fore_cast, main="")

Resources