linearly ranking values from 0:10 in r - r

I have the following dataset:
structure(list(G = c(NA, NA, -1.01182174807081, -1.01182174807081,
-1.01182174807081, -1.03501949560312, -1.03501949560312, -1.03501949560312,
-1.01189555194367, -1.01189555194367, -1.01189555194367, -1.03208191284692,
-1.03208191284692, -1.03208191284692, -1.00007825695672, -1.00007825695672,
-1.00007825695672, -1.03027247563088, -1.03027247563088, -1.03027247563088,
-0.999632960176179, -0.999632960176179, -0.999632960176179, -0.998570208055593,
-0.998570208055593, -0.998570208055593, -0.975978344319463, -0.975978344319463,
-0.975978344319463, -0.984342844790316, -0.984342844790316, -0.984342844790316,
-0.998450245287518, -0.998450245287518, -0.998450245287518, -1.11255680134788,
-1.11255680134788, -1.11255680134788, -1.14437105346841, -1.14437105346841,
-1.14437105346841, -1.24738311047776, -1.24738311047776, -1.24738311047776,
-1.28564738896258, -1.28564738896258, -1.28564738896258, -1.30225611704836,
-1.30225611704836, -1.30225611704836, -1.17181860494129, -1.17181860494129,
-1.17181860494129, -1.15687952410288, -1.15687952410288, -1.15687952410288,
-1.12078874426169, -1.12078874426169, -1.12078874426169, -1.12194837414298,
-1.12194837414298, -1.12194837414298, -1.1119085686834, -1.1119085686834,
-1.1119085686834, -1.11460209275208, -1.11460209275208, -1.11460209275208,
-1.14030482631462, -1.14030482631462, -1.14030482631462, -1.25693845068723,
-1.25693845068723, -1.25693845068723, -1.29636270710907, -1.29636270710907,
-1.29636270710907, -1.28630939351124, -1.28630939351124, -1.28630939351124,
-1.34123496736839, -1.34123496736839, -1.34123496736839, -1.30208113084414,
-1.30208113084414, -1.30208113084414, -1.27472858798502, -1.27472858798502,
-1.27472858798502, -1.2601313178257, -1.2601313178257, -1.2601313178257,
-1.25435070950356, -1.25435070950356, -1.25435070950356, -1.25446776571291,
-1.25446776571291, -1.25446776571291, -1.31782396761758, -1.31782396761758,
-1.31782396761758, -1.32404892123336, -1.32404892123336, -1.32404892123336,
-1.35533362583485, -1.35533362583485, -1.35533362583485, -1.32224476611552,
-1.32224476611552, -1.32224476611552, -1.37165859726789, -1.37165859726789,
-1.37165859726789, -1.32061051911721, -1.32061051911721, -1.32061051911721,
-1.26156328360682, -1.26156328360682, -1.26156328360682, -1.26156328360682,
-1.26156328360682, NA, NA)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -123L))
What I want is to rank every value 0 to 10, where 0 should equal the highest value (-0.9759783) and 10 should be the lowest value (-1.37166). Everything in between should be ranked linearly so that, for example, -1.25693845068723 should yield 7.1 and so on.
Thanks in advance.

Related

Find the average of rows with duplicated column value

If the GeneSymbol is duplicated (i.e., there are previous rows containing the string in the GeneSymbol column, calculate the average of the other columns of that row. Then, I want to assign the meth.kirp.cpg$GeneSymbol column as the new row names of meth.kirp.symbol.
meth.kirp.symbol <- aggregate(meth.kirp.cpg, by=meth.kirp.cpg$GeneSymbol,data=meth.kirp.cpg,FUN=mean)
meth.kirp.symbol <- na.omit(meth.kirp.symbol)
Traceback:
Error in !meth.kirp.cpg$GeneSymbol : invalid argument type
rownames(meth.kirp.symbol) <- meth.kirp.symbol$GeneSymbol
meth.kirp.symbol$GeneSymbol <- NULL
Sample data:
> dput(meth.kirp.cpg[1:100,200:203])
structure(list(TCGA.Y8.A8RZ.01A = c(0.497271965133314, 0.369704160054987,
0.891551980644717, 0.53916519146516, 0.452596179682145, 0.763243369017172,
0.158949338942062, 0.0114350980370701, 0.857172998292539, 0.934966165863031,
0.0472399882616577, 0.0198027126658891, 0.0537032844435588, 0.564211104629996,
0.927550968549496, 0.797624950816491, 0.0290697007131178, 0.595912681963104,
0.174701858916678, 0.882333378501306, 0.857440598542643, 0.937145001009176,
0.159643935623585, 0.0516599385847632, 0.0440610541422886, 0.986742471430344,
0.0164534273018356, 0.905466185196924, 0.831233179669209, 0.945308723924202,
0.889966942114764, 0.354918054240825, 0.013300356676493, 0.830128502759263,
0.823700653779667, 0.10271041258008, 0.0287034526533831, 0.0206566535596095,
0.600278705481019, 0.875119985046439, 0.0371692028405492, 0.0222508063515825,
0.93666315025643, 0.928345505993255, 0.901317044941454, 0.765949109446722,
0.0581920996836425, 0.0430643414149486, 0.90591121556885, 0.951186809441601,
0.980658657952396, 0.0808689550165884, 0.572734025228151, 0.0463712698649506,
0.192938671458161, 0.905133179842298, 0.154186184934303, 0.585848485208317,
0.898651062830721, 0.936272438882973, 0.448635246131194, 0.283554776533025,
0.0309419633482652, 0.861391852247259, 0.0658397100529213, 0.0675173265786392,
0.96281794820265, 0.0313479382790672, 0.0866228017859603, 0.929772217122431,
0.200029728957143, 0.706267849864433, 0.94823325183122, 0.0543243613691732,
0.809705102714619, 0.910219965210065, 0.953735039953166, 0.868080342290672,
0.332725938100749, 0.84324363592612, 0.198505346878334, 0.992801413007608,
0.0503582852070818, 0.475444599242399, 0.988297216865074, 0.926321491575251,
0.0243299898333789, 0.10772567979535, 0.892537448190976, 0.98896599725299,
0.305816605549349, 0.696841353119351, 0.807770532814146, 0.115817690804427,
0.0130874570078787, 0.837153421174282, 0.917049247300387, 0.0122380520755151,
0.912364270697772, 0.951585664581661), TCGA.Y8.A8S0.01A = c(0.264547845506278,
0.155993443463906, 0.90708922263186, 0.756216481105085, 0.740439258566013,
0.791640201668772, 0.455406433078148, 0.0140503539973426, 0.898152971615672,
0.942017289363471, 0.049036339456109, 0.0165762503059443, 0.0593335909473265,
0.459771444740498, 0.929336066827294, 0.948532354182067, 0.0181370789479238,
0.309340792232534, 0.444549689057808, 0.968706245954783, 0.911532818633905,
0.922085999840623, 0.439367515136192, 0.0341088658899809, 0.259555790896829,
0.987081295221313, 0.013467632667194, 0.935890204938304, 0.749182228512838,
0.955266815776283, 0.854718619922343, 0.192270767250957, 0.0103294109383117,
0.814778997430484, 0.884929086289906, 0.364141121626961, 0.0261130123662795,
0.0201970054665062, 0.613121306641491, 0.867830249077504, 0.0313157213491265,
0.0247935393251212, 0.911488850004792, 0.895214160236747, 0.52514961950261,
0.88376413256428, 0.0384672039105036, 0.0294663841757698, 0.957910054231064,
0.955637967662581, 0.980805007180895, 0.056939960969146, 0.737932777954196,
0.0318060005100734, 0.0397987294622703, 0.914995576026559, 0.238482151213353,
0.767237616032529, 0.939069872404913, 0.938081858296652, 0.440484138576205,
0.114954872159159, 0.0244136454763111, 0.846540100826359, 0.200658220716674,
0.0687237453669147, 0.974841732977847, 0.0278561439566069, 0.114556259287869,
0.944131549328849, 0.493585389693977, 0.480768780057962, 0.932741163713172,
0.216131694873378, 0.814313163672161, 0.928672085649515, 0.962443725743837,
0.74077045094838, 0.133424847325993, 0.862916554456606, 0.145580720195214,
0.992046334661351, 0.0436393256442202, 0.712662114242391, 0.990103320899525,
0.880978917772909, 0.0225238271112234, 0.116230435240584, 0.841150918912896,
0.987985943353706, 0.127354758970553, 0.898121601977617, 0.906792865660564,
0.0737140541126039, 0.009384930132621, 0.793174978739833, 0.912006490158477,
0.0139855016500958, 0.899386699555785, 0.954405724569427), TCGA.Y8.A8S1.01A = c(0.581694254362101,
0.18542567310602, 0.867542022665212, 0.581696896530406, 0.78744743737146,
0.389767299224826, 0.216960001070295, 0.0124187105565375, 0.856565918074359,
0.936457155497046, 0.0442067173962602, 0.0140296565558842, 0.249846574394466,
0.476357170192695, 0.919768286971888, 0.947576649507426, 0.0180436058702339,
0.832021246626068, 0.417883168882454, 0.97668892894152, 0.858942374669228,
0.908701674774902, 0.360605175695457, 0.0300050878088438, 0.0152722989237764,
0.986911029436886, 0.017968868244694, 0.916403999667678, 0.665473802275997,
0.894770076029211, 0.815937481683747, 0.505075619070648, 0.0100265844940471,
0.807220745685876, 0.808764855317654, 0.316721084000246, 0.0221128261277136,
0.0159144104679436, 0.841207551595894, 0.832097056965122, 0.0307025272327261,
0.0185995888430839, 0.916475132262134, 0.866934314703349, 0.877454940064029,
0.833363153320509, 0.0381805807655402, 0.0273586863112515, 0.941134508841013,
0.912364696768614, 0.979496335094356, 0.0978730283287029, 0.525086161575951,
0.0261062766734918, 0.0320956400558761, 0.853299258800261, 0.131541990462738,
0.52940082480104, 0.85502275403225, 0.894518042164208, 0.535297530625847,
0.4749856970718, 0.0169015303648868, 0.853076664003846, 0.147470852267928,
0.0467328218099492, 0.978302229003696, 0.0283296096497759, 0.0728218303634117,
0.87648102880048, 0.334033090095117, 0.680802308868236, 0.927680442837916,
0.0707104696817582, 0.770195537274174, 0.868009087459515, 0.951475963819618,
0.797689168093036, 0.683015763740223, 0.803432908458056, 0.191347383851541,
0.991395963746777, 0.0604147893723364, 0.874483310648752, 0.98062171660084,
0.83805259736689, 0.0247465538486677, 0.170932965706481, 0.842567160630419,
0.983614792589478, 0.800795162965799, 0.860170927275085, 0.890545098059859,
0.298079674760789, 0.0084611909392357, 0.73227051610062, 0.831245875309251,
0.0115215601617515, 0.784943936721062, 0.835800768909104), GeneSymbol = c("RBL2",
NA, "VDAC3", "ACTN1", "ATP2A1", "SFRP1", NA, "NIPA2", "MAN1B1",
"LRRC16A", "CNBP", "DDX55", "FAM81A", "KCNQ1", NA, "NPHP4", "MRPS25",
NA, NA, "MAEL", "PROX1", "ELOVL1", "LILRA6", "LOC283050", "NR5A2",
"CDK10", NA, "TMEM182", NA, "DNAJA2", "ATOH7", "LRFN1", "MRPL12",
"COL6A3", NA, "C8orf31", "RTTN", "CD2BP2", "SLMAP", NA, "NOV",
"MXD4", "SND1", "MUSTN1", "TAS1R3", "ITGAD", "SMARCC2", "C1orf114",
NA, "C1orf65", "DNAH17", "DAB1", NA, "SLBP", "CHCHD4", NA, "TNNT2",
"CASZ1", "CASZ1", "C3orf16", NA, "WFIKKN2", "CCDC45", NA, "MEOX2",
"CKLF", "TRANK1", "ZFP36", "SLC2A9", "MXRA7", "LOXL4", NA, "P2RX6P",
"SFRS7", NA, "EHMT1", "AGPAT3", "CDSN", NA, NA, "AGA", "LDHD",
"C14orf181", "LOC729176", "SH2B3", "MTMR7", "MT1F", "RSPO3",
"ANKRD11", "TDRD6", "WWP2", "OR1F2P", "SERPINB12", "DOK7", "SRCAP",
"AMDHD2", "DRG2", "TCTE3", "EFNB1", "FAM180B")), row.names = c("cg00000029",
"cg00000165", "cg00000236", "cg00000289", "cg00000292", "cg00000321",
"cg00000363", "cg00000622", "cg00000658", "cg00000721", "cg00000734",
"cg00000769", "cg00000905", "cg00000924", "cg00000948", "cg00000957",
"cg00001245", "cg00001249", "cg00001261", "cg00001349", "cg00001364",
"cg00001446", "cg00001510", "cg00001582", "cg00001583", "cg00001687",
"cg00001747", "cg00001791", "cg00001809", "cg00001854", "cg00001874",
"cg00002033", "cg00002116", "cg00002145", "cg00002190", "cg00002224",
"cg00002236", "cg00002406", "cg00002426", "cg00002449", "cg00002464",
"cg00002490", "cg00002531", "cg00002591", "cg00002593", "cg00002597",
"cg00002660", "cg00002719", "cg00002769", "cg00002808", "cg00002809",
"cg00002810", "cg00002837", "cg00003091", "cg00003173", "cg00003181",
"cg00003287", "cg00003345", "cg00003513", "cg00003529", "cg00003578",
"cg00003625", "cg00003784", "cg00003969", "cg00003994", "cg00004055",
"cg00004067", "cg00004072", "cg00004082", "cg00004089", "cg00004105",
"cg00004121", "cg00004192", "cg00004207", "cg00004209", "cg00004429",
"cg00004533", "cg00004562", "cg00004608", "cg00004773", "cg00004818",
"cg00004883", "cg00004939", "cg00004963", "cg00004979", "cg00004996",
"cg00005010", "cg00005040", "cg00005072", "cg00005083", "cg00005112",
"cg00005166", "cg00005215", "cg00005297", "cg00005306", "cg00005390",
"cg00005437", "cg00005543", "cg00005617", "cg00005619"), class = "data.frame")
As you have some NA's in GeneSymbol, you cannot use them as rownames unless you remove the NA's also.
This code identifies and calculates the mean of the duplicated and NA's rows,
then remove them from the data.frame and assign GeneSymbol as rownames
meth.kirp.duplicated.na <- data.frame(
mean = apply(subset(meth.kirp.cpg,
duplicated(GeneSymbol) | is.na(GeneSymbol),
select = -GeneSymbol), MARGIN = 1, mean),
is.na = with(meth.kirp.cpg, is.na(GeneSymbol)[
duplicated(GeneSymbol) | is.na(GeneSymbol)]))
meth.kirp.cpg <- subset(meth.kirp.cpg, !duplicated(GeneSymbol) & !is.na(GeneSymbol))
rownames(meth.kirp.cpg) <- meth.kirp.cpg$GeneSymbol
If I understand you correctly, you can loop over the rows and calculate an average only when GeneSymbol is a duplicate.
# create empty column for averages
meth.kirp.cpg$average = rep(NA, nrow(meth.kirp.cpg))
# fill column with row average for cases when `GeneSymbol` is a duplicate
for (r in 1:nrow(meth.kirp.cpg)) {
if (sum(na.omit(meth.kirp.cpg$GeneSymbol[r] == meth.kirp.cpg$GeneSymbol)) > 1){
meth.kirp.cpg$average[r] = mean(meth.kirp.cpg[r,1],
meth.kirp.cpg[r,2],
meth.kirp.cpg[r,3])
}
}

Arima model with Rolling Origin in R

I am working on a data set with 14 variables. I have used the Arima model with Rolling Origin but applying the rolling origin method on each variable every time is a bit slow and want to automate the process. I have tried to automate the process so that it gives me outputs for 14 models but it gives me an error. Please any help is appreciated.
Data:
structure(list(Date = structure(c(289094400, 297043200, 304992000,
312854400, 320716800, 328665600, 336614400, 344476800, 352252800,
360201600, 368150400, 376012800, 383788800, 391737600, 399686400,
407548800, 415324800, 423273600, 431222400, 439084800, 446947200,
454896000, 462844800, 470707200, 478483200, 486432000, 494380800,
502243200, 510019200, 517968000, 525916800, 533779200, 541555200,
549504000, 557452800, 565315200, 573177600, 581126400, 589075200,
596937600, 604713600, 612662400, 620611200, 628473600, 636249600,
644198400, 652147200, 660009600, 667785600, 675734400), tzone = "UTC", class = c("POSIXct",
"POSIXt")), NORTH = c(4.06976744186047, 5.51675977653633, 7.2799470549305,
4.75015422578655, 4.59363957597172, 3.15315315315317, 1.2008733624454,
-0.377562028047452, -0.108283703302655, 0.650406504065032, 0.969305331179318,
0.106666666666688, 3.09003729355352, 2.11886304909562, 2.32793522267207,
5.68743818001977, -1.46934955545156, 3.95611702127658, 5.19438987619354,
-0.0912012507600199, 2.81677896109541, 3.97412590369087, 1.30118326353028,
3.31553807249226, 1.32872294960955, 2.93700394923507, 0.908853875665812,
1.81241002546971, -1.3414545718222, 4.81772747317361, -3.4743890895067,
4.63823913990992, 0.857370960463727, 1.78620594713658, 0.527472527472524,
-4.05973562947765, -0.136726966764838, 3.16657890117607, 5.95161125667812,
8.01002055498458, 10.5501040737437, 13.4138468987035, 2.93371279497212,
8.84291046495554, -6.87764606265876, 2.90741287990725, 3.71548486856639,
1.23317430567388, -1.1153443739474, 4.31313207880924), YORKSANDTHEHUMBER = c(4.0121120363361,
5.45851528384282, 9.52380952380951, 6.04914933837431, 3.03030303030299,
5.42099192618225, 2.78993435448577, -0.53219797764768, 1.97966827180309,
1.15424973767052, 0.466804979253115, -1.96179659266907, 2.42232754081095,
0.719794344473031, -0.306278713629415, 3.37941628264209, 2.74393263992076,
3.91920555341303, 1.91585099967527, 0.892125625853447, 2.91888477848958,
3.78293078507868, 0.109815847271484, 6.83486625601216, 0.722691730511011,
3.56008625759656, -0.227160867754524, 2.69419041475355, -1.17134094520194,
2.78546324684064, 1.01487759630426, 1.54843356139717, 4.15602836879435,
4.43619773934357, -0.309698451507728, -1.45519947678222, -1.09839057574248,
9.08267346664877, 11.8913598474363, 13.9511229623114, 9.71243848306475,
7.66524473371739, 6.46801731884651, -2.26736490763654, -4.35729847494552,
-2.93870179974964, -7.72353426221536, -7.01127302722023, 2.02543627323513,
2.51245245873873), NORTHWEST = c(6.57894736842105, 6.95256660168939,
6.50060753341436, 5.5904164289789, 4.59211237169096, 4.70041322314051,
2.96003946719288, -1.38955438428365, 0.242954324586984, 2.18128938439167,
-0.853889943073994, -2.15311004784691, 0.929095354523226, 2.51937984496125,
0.189035916824195, 2.21698113207546, 2.51499769266268, 3.5066396578888,
1.77437592415414, 0.948636868643719, 4.60125296308836, 3.95775160859537,
-0.237455720347246, 4.218042765725, 2.79306600771276, 2.22545984338008,
0.709042970141798, 0.258269945161875, 0.663420142564747, 2.23655612423752,
1.69729803867784, 0.792339593378065, 2.82330902522246, 2.20899212700891,
1.48327338701976, -1.78151365931687, 1.8457608174996, 5.06380710500736,
7.57132625044768, 9.28561520321818, 9.51969943135663, 11.3671132539057,
10.5960954085668, -1.43026516363364, 3.55308627832826, 3.99351008518014,
-1.44138713566414, -0.165494414563527, 2.01304344107922, 1.70645628251555
), EASTMIDS = c(4.98489425981872, 8.20143884892085, 6.91489361702127,
5.22388059701494, 5.61465721040189, 4.64465584778958, 2.03208556149733,
0.314465408805028, 2.82131661442007, 0, 2.79471544715448, -0.939199209095414,
-1.14770459081835, 2.97829379101462, -0.68627450980392, 3.40572556762095,
3.42243436754175, 4.89223242719342, 0.730408764905171, 2.10107893242476,
2.31025926242835, 5.01798109893785, 0.382256908497274, 4.64894882982943,
3.04374194526571, 2.25491999264298, 0.651125980286367, 1.40105078809108,
2.87265165133409, 3.59418899472349, 1.76616504051596, 3.78627839708797,
3.9017974572556, 3.85473176612416, 0.0696479874633737, 1.45578980947134,
2.96698585107904, 12.8612275490659, 16.8142463597009, 10.6860102754148,
5.80782620275077, 2.65911542610573, -2.54295171544163, 4.66512121048756,
-3.66911045104132, -1.75382312052187, -3.61743042705271, -5.070772474025,
-1.21063610003222, 1.9530155970429), WESTMIDS = c(4.65838509316771,
4.74777448071216, 8.66855524079319, 6.56934306569344, 3.22896281800389,
3.17535545023698, 0.643086816720257, -1.36923779096303, 1.61962054604351,
2.00364298724953, -0.491071428571428, -2.78151637505608, 0, 2.39963082602676,
0.540784136998647, 1.83774092335275, 4.66989436619718, 1.82498633362771,
2.51909973157134, 0.644511581067457, 3.9503702221333, 3.15724626520867,
0.548671245147809, 4.19837410445824, 3.20983256145349, 1.12526319422872,
1.4028740144042, 0.434226470984247, -0.194389516372279, 2.32714328889485,
1.7360199527435, 3.3224734685978, 4.23339889482064, 5.79267379518974,
4.39964893406187, 0.374237288135615, 4.31199848701807, 13.9164443523531,
18.0050929925879, 6.07502745611839, 3.93976822755839, 4.07004176642259,
3.48434981192908, -1.92610381813166, 0.438451356717408, -0.103780578206083,
-3.0952145377791, -1.72381519612015, -2.02143896779759, 4.40768347678723
), EASTANGLIA = c(6.74525212835624, 8.58895705521476, 8.47457627118643,
10.7291666666667, 4.8447789275635, 4.84522207267835, -0.299529311082601,
1.45922746781116, 0.88832487309645, 0.29350104821803, -0.877926421404701,
1.64487557992411, -2.69709543568468, 3.49680170575694, 3.25504738360115,
2.39425379090184, 2.98519095869059, 4.36691137516082, 3.57868020304568,
1.66275772744776, 3.79450451070863, 4.52162951167727, 2.28203256419209,
4.17054552224914, 3.2439678284182, 4.76643873164257, 0.955633279171614,
2.91614381581101, 0.848198902642676, 5.02010671012167, 2.80551592962435,
5.64292321924145, 4.17550004608719, 9.7903026013095, 5.88709352460008,
3.07862089961185, 8.83080444493668, 14.1609281183215, 14.9330678829839,
-2.38242974223737, 1.8287757399192, 1.22633166874738, -5.71564382892894,
-5.25820956533587, -9.72515856236787, 0.957479010339489, -3.50481300299826,
-3.45549395738277, -0.828308094308001, -0.331408094033985), OUTERSEAST = c(6.7110371602884,
7.53638253638255, 9.47317544707589, 8.56512141280351, 3.82269215128102,
2.11515863689776, 1.64940544687381, -1.73584905660378, 1.34408602150539,
1.78097764304659, 0.446760982874161, -1.26019273535953, 0.150150150150159,
3.11094452773611, 1.4176663031625, 2.54480286738352, 5.56448794127927,
4.89371564797033, 3.88257575757575, 1.85961713764815, 5.54859495256845,
4.29879599796508, 2.00525702517411, 3.63679834232127, 3.44509381728699,
3.46664684309643, 1.93988743863012, 2.50440502760482, 2.96578121060713,
4.47634947134114, 4.50826657576274, 4.92742395824838, 5.38770910645244,
7.13653626341212, 6.15524925576032, 1.08283352245096, 6.66955322492704,
9.69075574665124, 11.4606033194907, 3.4233015677836, 1.10095233565968,
1.65461280649144, -3.58737650679069, -5.85546129756061, -4.98846560711691,
-2.32068359558401, -5.55914140928629, -4.66925504224286, -1.07093896112692,
2.07357059157311), OUTERMET = c(4.54545454545458, 6.58505698607005,
7.36633663366336, 7.08225746956843, 4.3747847054771, 1.68316831683168,
1.00616682895164, -1.28534704370181, 2.01822916666665, 0.797702616464613,
0.949667616334271, -0.940733772342415, 1.10794555238999, 2.19160926737633,
2.84926470588237, 2.62138814417631, 5.02467343976781, 5.65213786241397,
3.22555328833776, 3.73552294786995, 5.05948745510956, 4.28797321179426,
2.86300392436674, 2.60339894216597, 4.28031183318191, 3.43199821714381,
3.34554286721641, 3.04770569170409, 1.65167650683293, 4.62120252591965,
6.34025700005186, 6.1931790459772, 8.10781836281492, 6.14401677315165,
5.88313802952244, 0.112183931227468, 4.21036727396348, 5.85740693754756,
8.61496319123439, 2.24246818616477, 2.39678510128783, 1.57885756155336,
-2.68472955079939, -5.09925369345585, -6.23990242127901, -2.51851513733724,
-2.72874133732908, -5.45172276846427, 0.20833593462305, 2.61721355963614
), LONDON = c(8.11719500480309, 10.3065304309196, 6.32299637535239,
7.65151515151515, 1.30190007037299, 2.1535255296978, -0.204012240734436,
-0.306643952299836, 0.786056049213951, 1.18684299762631, 1.00536193029493,
-2.85335102853352, 2.76639344262296, 2.06048521103356, 1.23738196027352,
2.70183338694115, 3.30410272471031, 5.76322570865546, 4.73255747291176,
1.98428989791171, 6.03563952552197, 4.88977753030802, 2.12581135535556,
4.43247330120026, 5.42986425339366, 3.96781115879828, 3.43247538648888,
4.0668901660281, 4.09587727708534, 4.81707991010573, 7.42869193863026,
6.70069362648866, 6.67699006500675, 7.43184006668679, 5.53177257525084,
-1.06737656081638, 1.7605678920595, 5.86902048679756, 6.75919979067056,
0.943616938313976, 1.29679498499027, 1.95787891003782, -1.64030775806797,
-2.62806236080178, -2.6208912592328, -4.49717565910836, -5.18403877531433,
-5.57502752084625, -0.947552316580683, 0.978175016770521), SOUTHWEST = c(6.17577197149644,
7.71812080536912, 7.63239875389407, 9.45489628557649, 2.46804759806079,
2.19354838709679, 1.72558922558922, 0.248241621845247, 1.48576145274456,
2.03334688897925, -0.677560781187733, -2.3274478330658, 1.80772391125718,
2.42130750605327, 1.85185185185186, 0.928433268858785, 5.95247221157533,
4.38447346525341, 3.30272049904696, 2.25107353730542, 3.86823714688802,
2.04371722787289, 3.04596811639065, 4.19057346270538, 2.45646407565451,
2.17525889239081, 2.83400809716597, 1.58015962290428, 2.77894958869438,
4.08650146221331, 4.40418977202712, 2.87285774987016, 3.86424654076504,
5.69560126372535, 5.04170063334797, 1.07854257457266, 6.75066443547593,
13.56963706108, 16.2190250397843, 2.62121000419169, -0.940827274460141,
2.85066318466084, -0.886020125887025, -6.46387832699618, -3.51150320013839,
-0.306262698697259, 0.555963495227118, -7.19650681052728, -1.76899526612503,
0.528003461834023), WALES = c(6.09418282548476, 8.35509138381203,
7.40963855421687, 7.01065619742007, 1.15303983228513, 3.47150259067357,
-0.150225338007013, 0.852557673019058, 0.944803580308295, -1.13300492610835,
0.946686596910786, -2.17176702862782, 3.98587285570131, 0.485201358563789,
3.62143891839691, 1.63094128611373, 1.61852361302152, 4.32251951450617,
1.28887158859911, 0.68747598104105, 3.71925360474978, 4.66941979801284,
1.44927536231884, 1.05121293800539, 1.67663757954501, 2.9419480568152,
-0.422309596621509, 2.67987715706347, 0.0249243368346056, 2.03260714794249,
1.14433241461116, 3.01472870890965, 0.7768290641219, 3.81433365451707,
-0.140822531605095, -2.99349379827568, 4.11669475005782, 4.95668454288706,
12.973544973545, 15.3990258523792, 9.25324675324674, 6.63977924007642,
0.236872486962066, -0.381277677383487, 0.681750224259938, -2.67091690260756,
-5.39078074779283, -3.51337404317537, 0.996191624080064, 2.8524564276044
), SCOTLAND = c(5.15222482435597, 4.12026726057908, 5.40106951871658,
8.67579908675796, -0.280112044817908, 2.94943820224719, 1.04592996816735,
1.21512151215122, 1.33392618941751, 3.59806932865292, 0.974163490046604,
0.125838926174496, 1.46627565982404, 3.42691990090835, -0.838323353293421,
1.97262479871176, 3.40702724042636, 4.30649410147751, 2.44866586142527,
1.93997856377279, 2.09581887638873, 4.22573890357352, 0.833278440155458,
4.15155969296095, 2.01655899140689, 1.93980755633434, 0.325693606755129,
0.796561260069754, -0.381713535919834, 2.90974405029185, 0.802862378916138,
0.473263498109834, 1.33268231036562, 0.742609336470062, 0.427651014264418,
-2.00028015128168, -2.46419484863213, 3.18590814502184, 4.33732886439812,
3.78406337625565, 4.59302783096821, 9.65541455585091, 7.16082700576343,
2.74890619997868, -6.81926759861247, 3.2880071333036, 2.69558648969462,
-2.78454942837929, 1.79123210602768, 2.88825864878425), NIRELAND = c(4.54545454545454,
4.94752623688156, 4.42857142857145, 2.96397628818967, 6.06731620903454,
0.0835073068893502, -1.66875260742594, -2.96987696224015, -1.18058592041975,
-0.884955752212393, -1.74107142857143, -0.545206724216265, 1.96436729100047,
-0.224014336917564, -1.84104176021554, 1.6010978956999, 1.42278253039172,
1.97993429814437, 1.29287828660979, 1.61158623060724, 2.28387751649466,
1.84005954349984, 1.79057208981284, 2.22177901874749, 2.88757950598978,
-0.731975575530031, 3.07939176281808, -0.0593031875463392, -1.05696484201158,
3.40717418194087, 1.07655502392344, -1.70701093778018, -2.34959319931409,
6.56454324677751, -1.80912979454455, -4.90966221523961, 0.319176899102556,
1.67315466387184, -2.88259765121672, 2.95678544351781, -0.54123711340205,
4.15355569540591, -1.90510040874357, 0.923946519801462, 4.1035398865513,
-2.3519674449081, -5.50238389546177, 7.24670179766041, 2.75090864790844,
0.446509889559553), UK = c(5.76890543055322, 7.20302836425676,
7.39543442582184, 7.22885986848197, 3.23472252213347, 2.95766398929048,
1.20271423347285, -0.554061107319231, 0.98913965036942, 1.55113136643479,
0.373986300291293, -1.61195434757029, 1.59052858167903, 2.07573082205217,
1.17628969016684, 2.44680851063832, 2.84453345201007, 4.10010457610617,
2.88208396840793, 1.58922558922557, 3.67559326527908, 3.90013106997858,
1.36611181194425, 4.12505691303686, 2.02017257462689, 2.93167985827357,
1.54068234183715, 2.12149379408387, 0.594313861969269, 3.83755588673622,
3.33948434056075, 3.50933756603259, 3.25378570059421, 5.14920870654849,
3.36548010504709, -0.177206541696886, 1.65971553844507, 8.51865098567251,
11.0759984490113, 5.32351247098249, 3.99880682100659, 4.55095927082668,
0.864171188197283, -2.04898834977862, -3.10383660120637, -1.01415357182659,
-2.94496091613858, -4.06343734981687, -0.677156948752485, 1.59717017296902
)), row.names = c(NA, -50L), class = c("tbl_df", "tbl", "data.frame"
))
This manual code works:
y <- data2$NORTH
ourCall <- "predict(arima(x=data,order=c(1,0,0)),n.ahead=h)"
ourValue <- c("pred")
returnedValues1 <- ro(y, h=4, origins = 8,
call=ourCall, value=ourValue)
returnedValues1$actuals
returnedValues1$holdout
returnedValues1$pred
But this doesn't:
y <- data2
y %<>% dplyr::select(-Date)
ourCall <- "predict(arima(x=data,order=c(1,0,0)),n.ahead=h)"
ourValue <- c("pred")
ar_ro_model_4 = apply(y,2,function(x){
return(
list(
returnedValues1 <- ro(y, h=4, origins = 8,
call=ourCall, value=ourValue)
))
} )
ar_ro_model_4

Subset/filter dataframe with comma separated variables in each row

I would like to subset a data.frame that has comma separated variables in each row based on on another data.frame.
df1 (to subset) looks like:
structure(list(Group = c("OG0000000", "OG0000001", "OG0000002",
"OG0000003", "OG0000005", "OG0000005"), C1 = c("K10G4.10, K03D7.7, T06E6.13, F09C3.4, Y47D3A.2, F10A3.17, Y36E3A.1, F44G3.8b, Y67A10A.4, F10A3.2, Y9C9A.12, Y61B8A.4, T09F5.11, C25D7.4a, Y75B8A.21, Y102A5C.19, F47H4.9, C38D9.6, F47H4.4, Y9C9A.8, C02H6.2, C08F11.5a, C38D9.9, F31E9.3, F36G9.14, B0391.9, F14H3.7, M162.11, Y37H2A.12a, Y45F10C.3, Y47H9C.10, Y37H2A.6, Y37H2A.5b, Y37H2A.7, F57G4.8, Y37H2A.18, Y38A10A.4, Y37H2C.3, Y47H9C.12, F56C3.2, C31C9.3, B0391.11a, Y73B3A.22, B0391.5, Y102A5C.1, Y73B3A.15, B0391.6, C38D9.1, C38D9.7, F47H4.8, F44G3.12, F44G3.14, B0511.3, C08E3.9, C08E3.10a, C08E3.6, F45C12.8, ZK1290.9, C36C9.3, T06C12.4, C08E3.7, C08E3.12, C08E3.8, F35E12.3, Y75B12B.1b, F57G4.10, W04E12.1, F28F8.4, F28F8.8a, C17C3.6, C17C3.5, Y102A5C.9, Y102A5C.13, Y113G7B.6, Y113G7B.7, M162.8, Y113G7B.3, Y113G7B.1b, F59A1.7, Y37H2A.4, Y59A8B.11b, Y102A5C.14, Y113G7B.5b, Y113G7B.4, C33E10.2, F14D2.13b, Y57G11C.499",
"Y67A10A.5, H03G16.4, T12B5.7, Y119D3A.1, Y82E9BL.14, Y82E9BL.18, Y119D3B.19, ZC47.7, Y82E9BL.13, T24C2.4, T06E6.15, Y22D7AR.9, Y119D3B.4, Y119D3B.22, Y119D3B.6, T25E12.12, Y22D7AR.2, cTel54X.1, Y82E9BR.12, T20H9.1, Y54F10BM.15, cTel54X.2, Y82E9BL.17, Y119D3A.2, Y82E9BL.7, Y82E9BL.4, F10A3.3, ZC47.4, ZC47.5, Y119D3A.3, Y119D3A.4, ZC47.14, ZC47.3, ZC47.6, Y54F10BM.10, Y82E9BL.11, Y82E9BL.10, Y82E9BL.8, F42G2.8, T13F3.5, T08E11.7, Y82E9BL.15, Y22D7AR.11, T12B5.3, Y54F10BM.5, T12B5.4, C39B5.7, Y54F10BM.20, T20H9.4, Y119D3B.9, Y82E9BL.19, T12B5.5, T12B5.11, F54D10.2, B0294.3, Y119D3B.8, F09C6.2, F09C6.15, F09C6.6, C39B5.9, Y54F10BL.1, T20H9.2, F52D2.1, Y59E1A.1, Y54F10BM.4, C39B5.3, Y54F10BM.11, C17B7.11, T28A11.21, Y119D3B.7, T20H9.3, F54B8.3, C39B5.4, Y54F10BM.7, T12B5.1, F07G6.6, F31F4.15a, ZC47.13a, T12B5.2, F07G6.7, T12B5.6b, T12B5.8, T12B5.10",
"R08A2.4", "F09C3.3, F09C3.5, F49B2.2, Y40B1B.3, Y17G9B.2, F29A7.1a, F29A7.2, F08D12.8, F08D12.6, F08D12.11, F08D12.10, F08D12.9, F53C3.2, F15A4.13, C33E10.8, ZK909.5, T02G5.14, F49B2.1, Y63D3A.9a, C52E2.1, C16C4.6, C52E2.6, C52E2.7, F49B2.7, Y63D3A.3, Y8A9A.5, Y63D3A.2, W03D2.2, F30B5.11, F08D12.15, Y63D3A.10, F15E6.5, M116.1, M116.4, K08E4.8, Y41D4A.3, E04A4.1, Y17G9B.7a, H02I12.2, R08C7.13, R08C7.9, F40F4.1, H24O09.2, C33E10.1, F38H4.2, F07E5.1, C08F8.15, M01D1.12, C41H7.8, C33F10.13, C08F8.5, R07H5.7, C44B9.6, R17.1, T17A3.6, T17A3.4, T17A3.3, T17A3.7",
"E03H12.6", "B0205.2b, F46B3.11, F19B2.8, C32H11.2, C35D6.9a, Y7A9C.7, C09G12.16, W05E7.2, F31E9.5, H12I19.1, H12I19.7, F58E2.9, F56D6.5a, F56D6.4, C39B5.1, F56D6.7, K03D3.4, C04C3.1, Y57G7A.12, Y57G7A.7, C17F4.10, F40D4.9a, Y7A9C.9, C09G12.3, C09G12.2, K03D3.1, C09G12.11, C09G12.10, C18D4.5, K03D3.11, C35D6.13a, C09G12.6, C09G12.15, C35D6.10, K03D3.12, Y102A5C.25, Y68A4A.2, F20E11.1, C55A1.12, H12I19.2, C08F11.9"
), C2 = c("WBGene00270785", "WBGene00088344", "WBGene00039349, WBGene00027461, WBGene00303255, WBGene00027526, WBGene00027525, WBGene00270549, WBGene00027465, WBGene00027468, WBGene00037996, WBGene00041363, WBGene00041365, WBGene00041367, WBGene00037998, WBGene00042987, WBGene00041298, WBGene00041292, WBGene00037999, WBGene00270642, WBGene00034189, WBGene00086898, WBGene00034195, WBGene00270949, WBGene00027324, WBGene00036268, WBGene00027323, WBGene00027443, WBGene00027444, WBGene00027441, CBG22632, WBGene00088690, WBGene00088694, WBGene00088672, WBGene00042834, WBGene00027469, WBGene00027466, WBGene00042618, WBGene00034515, WBGene00041149, WBGene00027326, WBGene00024635, WBGene00042835, WBGene00037338, WBGene00270641, WBGene00271232, WBGene00042721, WBGene00042527, WBGene00042719, WBGene00027540, WBGene00041348, WBGene00271293, WBGene00041345, WBGene00041343, WBGene00042525, WBGene00036831, WBGene00027296, WBGene00027439, WBGene00088721, WBGene00271072, WBGene00271223, WBGene00042617, WBGene00037910, WBGene00042702, WBGene00041148, WBGene00087676",
"WBGene00041416", "CBG11630", "CBG13745")), row.names = c(NA,
-6L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x7ff0ad8056e0>)
column to subset is C1.
df2 (use to subset):
structure(list(V1 = c("K10G4.10", "H03G16.4", "T04B8.3", "F58G1.6",
"T21G5.5", "E03H12.6")), row.names = c(NA, -6L), class = c("data.table",
"data.frame"), .internal.selfref = <pointer: 0x7ff0ad8056e0>)
If I use df1$C1 %in% df2$V1, it finds B0024.2 and Y53F4B.33 but not the other two because they are in a row that has other comma separated variables.
I need it to return all the column data for the subsetted rows.
You can create a regex pattern using df2$V1 -
result <- subset(df1, grepl(sprintf('\\b(%s)\\b', paste0(df2$V1, collapse = '|')), C1))
where -
sprintf('\\b(%s)\\b', paste0(df2$V1, collapse = '|'))
#[1] "\\b(B0024.2|Y53F4B.33|Y53F4B.32|F58E6.4)\\b"
So it will select the row from df1 if C1 contains any of these values in it.

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="")

GGPlot - how to format x-axis for stopwatch like times

This seems relatively straightforward and possibly doable with scale_x_datetime or scale_x_discrete.
I have a column with time increments like on a stopwatch:
[1] 0:00:01 0:00:02 0:00:03 0:00:04 0:00:05 0:00:06
1800 Levels: 0:00:01 0:00:02 0:00:03 0:00:04 0:00:05 0:00:06 0:00:07 ... 0:30:00
Using ggplot how can I set the x-axis labels for 30 second intervals?
Reproducible data:
structure(list(`somedata$Time` = structure(1:4, .Label = c("0:00:01",
"0:00:02", "0:00:03", "0:00:04", "0:00:05", "0:00:06", "0:00:07",
"0:00:08", "0:00:09", "0:00:10", "0:00:11", "0:00:12", "0:00:13",
"0:00:14", "0:00:15", "0:00:16", "0:00:17", "0:00:18", "0:00:19",
"0:00:20", "0:00:21", "0:00:22", "0:00:23", "0:00:24", "0:00:25",
"0:00:26", "0:00:27", "0:00:28", "0:00:29", "0:00:30", "0:00:31",
"0:00:32", "0:00:33", "0:00:34", "0:00:35", "0:00:36", "0:00:37",
"0:00:38", "0:00:39", "0:00:40", "0:00:41", "0:00:42", "0:00:43",
"0:00:44", "0:00:45", "0:00:46", "0:00:47", "0:00:48", "0:00:49",
"0:00:50", "0:00:51", "0:00:52", "0:00:53", "0:00:54", "0:00:55",
"0:00:56", "0:00:57", "0:00:58", "0:00:59", "0:01:00", "0:01:01",
"0:01:02", "0:01:03", "0:01:04", "0:01:05", "0:01:06", "0:01:07",
"0:01:08", "0:01:09", "0:01:10", "0:01:11", "0:01:12", "0:01:13",
"0:01:14", "0:01:15", "0:01:16", "0:01:17", "0:01:18", "0:01:19",
"0:01:20", "0:01:21", "0:01:22", "0:01:23", "0:01:24", "0:01:25",
"0:01:26", "0:01:27", "0:01:28", "0:01:29", "0:01:30", "0:01:31",
"0:01:32", "0:01:33", "0:01:34", "0:01:35", "0:01:36", "0:01:37",
"0:01:38", "0:01:39", "0:01:40", "0:01:41", "0:01:42", "0:01:43",
"0:01:44", "0:01:45", "0:01:46", "0:01:47", "0:01:48", "0:01:49",
"0:01:50", "0:01:51", "0:01:52", "0:01:53", "0:01:54", "0:01:55",
"0:01:56", "0:01:57", "0:01:58", "0:01:59", "0:02:00", "0:02:01",
"0:02:02", "0:02:03", "0:02:04", "0:02:05", "0:02:06", "0:02:07",
"0:02:08", "0:02:09", "0:02:10", "0:02:11", "0:02:12", "0:02:13",
"0:02:14", "0:02:15", "0:02:16", "0:02:17", "0:02:18", "0:02:19",
"0:02:20", "0:02:21", "0:02:22", "0:02:23", "0:02:24", "0:02:25",
"0:02:26", "0:02:27", "0:02:28", "0:02:29", "0:02:30", "0:02:31",
"0:02:32", "0:02:33", "0:02:34", "0:02:35", "0:02:36", "0:02:37",
"0:02:38", "0:02:39", "0:02:40", "0:02:41", "0:02:42", "0:02:43",
"0:02:44", "0:02:45", "0:02:46", "0:02:47", "0:02:48", "0:02:49",
"0:02:50", "0:02:51", "0:02:52", "0:02:53", "0:02:54", "0:02:55",
"0:02:56", "0:02:57", "0:02:58", "0:02:59", "0:03:00", "0:03:01",
"0:03:02", "0:03:03", "0:03:04", "0:03:05", "0:03:06", "0:03:07",
"0:03:08", "0:03:09", "0:03:10", "0:03:11", "0:03:12", "0:03:13",
"0:03:14", "0:03:15", "0:03:16", "0:03:17", "0:03:18", "0:03:19",
"0:03:20", "0:03:21", "0:03:22", "0:03:23", "0:03:24", "0:03:25",
"0:03:26", "0:03:27", "0:03:28", "0:03:29", "0:03:30", "0:03:31",
"0:03:32", "0:03:33", "0:03:34", "0:03:35", "0:03:36", "0:03:37",
"0:03:38", "0:03:39", "0:03:40", "0:03:41", "0:03:42", "0:03:43",
"0:03:44", "0:03:45", "0:03:46", "0:03:47", "0:03:48", "0:03:49",
"0:03:50", "0:03:51", "0:03:52", "0:03:53", "0:03:54", "0:03:55",
"0:03:56", "0:03:57", "0:03:58", "0:03:59", "0:04:00", "0:04:01",
"0:04:02", "0:04:03", "0:04:04", "0:04:05", "0:04:06", "0:04:07",
"0:04:08", "0:04:09", "0:04:10", "0:04:11", "0:04:12", "0:04:13",
"0:04:14", "0:04:15", "0:04:16", "0:04:17", "0:04:18", "0:04:19",
"0:04:20", "0:04:21", "0:04:22", "0:04:23", "0:04:24", "0:04:25",
"0:04:26", "0:04:27", "0:04:28", "0:04:29", "0:04:30", "0:04:31",
"0:04:32", "0:04:33", "0:04:34", "0:04:35", "0:04:36", "0:04:37",
"0:04:38", "0:04:39", "0:04:40", "0:04:41", "0:04:42", "0:04:43",
"0:04:44", "0:04:45", "0:04:46", "0:04:47", "0:04:48", "0:04:49",
"0:04:50", "0:04:51", "0:04:52", "0:04:53", "0:04:54", "0:04:55",
"0:04:56", "0:04:57", "0:04:58", "0:04:59", "0:05:00", "0:05:01",
"0:05:02", "0:05:03", "0:05:04", "0:05:05", "0:05:06", "0:05:07",
"0:05:08", "0:05:09", "0:05:10", "0:05:11", "0:05:12", "0:05:13",
"0:05:14", "0:05:15", "0:05:16", "0:05:17", "0:05:18", "0:05:19",
"0:05:20", "0:05:21", "0:05:22", "0:05:23", "0:05:24", "0:05:25",
"0:05:26", "0:05:27", "0:05:28", "0:05:29", "0:05:30", "0:05:31",
"0:05:32", "0:05:33", "0:05:34", "0:05:35", "0:05:36", "0:05:37",
"0:05:38", "0:05:39", "0:05:40", "0:05:41", "0:05:42", "0:05:43",
"0:05:44", "0:05:45", "0:05:46", "0:05:47", "0:05:48", "0:05:49",
"0:05:50", "0:05:51", "0:05:52", "0:05:53", "0:05:54", "0:05:55",
"0:05:56", "0:05:57", "0:05:58", "0:05:59", "0:06:00", "0:06:01",
"0:06:02", "0:06:03", "0:06:04", "0:06:05", "0:06:06", "0:06:07",
"0:06:08", "0:06:09", "0:06:10", "0:06:11", "0:06:12", "0:06:13",
"0:06:14", "0:06:15", "0:06:16", "0:06:17", "0:06:18", "0:06:19",
"0:06:20", "0:06:21", "0:06:22", "0:06:23", "0:06:24", "0:06:25",
"0:06:26", "0:06:27", "0:06:28", "0:06:29", "0:06:30", "0:06:31",
"0:06:32", "0:06:33", "0:06:34", "0:06:35", "0:06:36", "0:06:37",
"0:06:38", "0:06:39", "0:06:40", "0:06:41", "0:06:42", "0:06:43",
"0:06:44", "0:06:45", "0:06:46", "0:06:47", "0:06:48", "0:06:49",
"0:06:50", "0:06:51", "0:06:52", "0:06:53", "0:06:54", "0:06:55",
"0:06:56", "0:06:57", "0:06:58", "0:06:59", "0:07:00", "0:07:01",
"0:07:02", "0:07:03", "0:07:04", "0:07:05", "0:07:06", "0:07:07",
"0:07:08", "0:07:09", "0:07:10", "0:07:11", "0:07:12", "0:07:13",
"0:07:14", "0:07:15", "0:07:16", "0:07:17", "0:07:18", "0:07:19",
"0:07:20", "0:07:21", "0:07:22", "0:07:23", "0:07:24", "0:07:25",
"0:07:26", "0:07:27", "0:07:28", "0:07:29", "0:07:30", "0:07:31",
"0:07:32", "0:07:33", "0:07:34", "0:07:35", "0:07:36", "0:07:37",
"0:07:38", "0:07:39", "0:07:40", "0:07:41", "0:07:42", "0:07:43",
"0:07:44", "0:07:45", "0:07:46", "0:07:47", "0:07:48", "0:07:49",
"0:07:50", "0:07:51", "0:07:52", "0:07:53", "0:07:54", "0:07:55",
"0:07:56", "0:07:57", "0:07:58", "0:07:59", "0:08:00", "0:08:01",
"0:08:02", "0:08:03", "0:08:04", "0:08:05", "0:08:06", "0:08:07",
"0:08:08", "0:08:09", "0:08:10", "0:08:11", "0:08:12", "0:08:13",
"0:08:14", "0:08:15", "0:08:16", "0:08:17", "0:08:18", "0:08:19",
"0:08:20", "0:08:21", "0:08:22", "0:08:23", "0:08:24", "0:08:25",
"0:08:26", "0:08:27", "0:08:28", "0:08:29", "0:08:30", "0:08:31",
"0:08:32", "0:08:33", "0:08:34", "0:08:35", "0:08:36", "0:08:37",
"0:08:38", "0:08:39", "0:08:40", "0:08:41", "0:08:42", "0:08:43",
"0:08:44", "0:08:45", "0:08:46", "0:08:47", "0:08:48", "0:08:49",
"0:08:50", "0:08:51", "0:08:52", "0:08:53", "0:08:54", "0:08:55",
"0:08:56", "0:08:57", "0:08:58", "0:08:59", "0:09:00", "0:09:01",
"0:09:02", "0:09:03", "0:09:04", "0:09:05", "0:09:06", "0:09:07",
"0:09:08", "0:09:09", "0:09:10", "0:09:11", "0:09:12", "0:09:13",
"0:09:14", "0:09:15", "0:09:16", "0:09:17", "0:09:18", "0:09:19",
"0:09:20", "0:09:21", "0:09:22", "0:09:23", "0:09:24", "0:09:25",
"0:09:26", "0:09:27", "0:09:28", "0:09:29", "0:09:30", "0:09:31",
"0:09:32", "0:09:33", "0:09:34", "0:09:35", "0:09:36", "0:09:37",
"0:09:38", "0:09:39", "0:09:40", "0:09:41", "0:09:42", "0:09:43",
"0:09:44", "0:09:45", "0:09:46", "0:09:47", "0:09:48", "0:09:49",
"0:09:50", "0:09:51", "0:09:52", "0:09:53", "0:09:54", "0:09:55",
"0:09:56", "0:09:57", "0:09:58", "0:09:59", "0:10:00", "0:10:01",
"0:10:02", "0:10:03", "0:10:04", "0:10:05", "0:10:06", "0:10:07",
"0:10:08", "0:10:09", "0:10:10", "0:10:11", "0:10:12", "0:10:13",
"0:10:14", "0:10:15", "0:10:16", "0:10:17", "0:10:18", "0:10:19",
"0:10:20", "0:10:21", "0:10:22", "0:10:23", "0:10:24", "0:10:25",
"0:10:26", "0:10:27", "0:10:28", "0:10:29", "0:10:30", "0:10:31",
"0:10:32", "0:10:33", "0:10:34", "0:10:35", "0:10:36", "0:10:37",
"0:10:38", "0:10:39", "0:10:40", "0:10:41", "0:10:42", "0:10:43",
"0:10:44", "0:10:45", "0:10:46", "0:10:47", "0:10:48", "0:10:49",
"0:10:50", "0:10:51", "0:10:52", "0:10:53", "0:10:54", "0:10:55",
"0:10:56", "0:10:57", "0:10:58", "0:10:59", "0:11:00", "0:11:01",
"0:11:02", "0:11:03", "0:11:04", "0:11:05", "0:11:06", "0:11:07",
"0:11:08", "0:11:09", "0:11:10", "0:11:11", "0:11:12", "0:11:13",
"0:11:14", "0:11:15", "0:11:16", "0:11:17", "0:11:18", "0:11:19",
"0:11:20", "0:11:21", "0:11:22", "0:11:23", "0:11:24", "0:11:25",
"0:11:26", "0:11:27", "0:11:28", "0:11:29", "0:11:30", "0:11:31",
"0:11:32", "0:11:33", "0:11:34", "0:11:35", "0:11:36", "0:11:37",
"0:11:38", "0:11:39", "0:11:40", "0:11:41", "0:11:42", "0:11:43",
"0:11:44", "0:11:45", "0:11:46", "0:11:47", "0:11:48", "0:11:49",
"0:11:50", "0:11:51", "0:11:52", "0:11:53", "0:11:54", "0:11:55",
"0:11:56", "0:11:57", "0:11:58", "0:11:59", "0:12:00", "0:12:01",
"0:12:02", "0:12:03", "0:12:04", "0:12:05", "0:12:06", "0:12:07",
"0:12:08", "0:12:09", "0:12:10", "0:12:11", "0:12:12", "0:12:13",
"0:12:14", "0:12:15", "0:12:16", "0:12:17", "0:12:18", "0:12:19",
"0:12:20", "0:12:21", "0:12:22", "0:12:23", "0:12:24", "0:12:25",
"0:12:26", "0:12:27", "0:12:28", "0:12:29", "0:12:30", "0:12:31",
"0:12:32", "0:12:33", "0:12:34", "0:12:35", "0:12:36", "0:12:37",
"0:12:38", "0:12:39", "0:12:40", "0:12:41", "0:12:42", "0:12:43",
"0:12:44", "0:12:45", "0:12:46", "0:12:47", "0:12:48", "0:12:49",
"0:12:50", "0:12:51", "0:12:52", "0:12:53", "0:12:54", "0:12:55",
"0:12:56", "0:12:57", "0:12:58", "0:12:59", "0:13:00", "0:13:01",
"0:13:02", "0:13:03", "0:13:04", "0:13:05", "0:13:06", "0:13:07",
"0:13:08", "0:13:09", "0:13:10", "0:13:11", "0:13:12", "0:13:13",
"0:13:14", "0:13:15", "0:13:16", "0:13:17", "0:13:18", "0:13:19",
"0:13:20", "0:13:21", "0:13:22", "0:13:23", "0:13:24", "0:13:25",
"0:13:26", "0:13:27", "0:13:28", "0:13:29", "0:13:30", "0:13:31",
"0:13:32", "0:13:33", "0:13:34", "0:13:35", "0:13:36", "0:13:37",
"0:13:38", "0:13:39", "0:13:40", "0:13:41", "0:13:42", "0:13:43",
"0:13:44", "0:13:45", "0:13:46", "0:13:47", "0:13:48", "0:13:49",
"0:13:50", "0:13:51", "0:13:52", "0:13:53", "0:13:54", "0:13:55",
"0:13:56", "0:13:57", "0:13:58", "0:13:59", "0:14:00", "0:14:01",
"0:14:02", "0:14:03", "0:14:04", "0:14:05", "0:14:06", "0:14:07",
"0:14:08", "0:14:09", "0:14:10", "0:14:11", "0:14:12", "0:14:13",
"0:14:14", "0:14:15", "0:14:16", "0:14:17", "0:14:18", "0:14:19",
"0:14:20", "0:14:21", "0:14:22", "0:14:23", "0:14:24", "0:14:25",
"0:14:26", "0:14:27", "0:14:28", "0:14:29", "0:14:30", "0:14:31",
"0:14:32", "0:14:33", "0:14:34", "0:14:35", "0:14:36", "0:14:37",
"0:14:38", "0:14:39", "0:14:40", "0:14:41", "0:14:42", "0:14:43",
"0:14:44", "0:14:45", "0:14:46", "0:14:47", "0:14:48", "0:14:49",
"0:14:50", "0:14:51", "0:14:52", "0:14:53", "0:14:54", "0:14:55",
"0:14:56", "0:14:57", "0:14:58", "0:14:59", "0:15:00", "0:15:01",
"0:15:02", "0:15:03", "0:15:04", "0:15:05", "0:15:06", "0:15:07",
"0:15:08", "0:15:09", "0:15:10", "0:15:11", "0:15:12", "0:15:13",
"0:15:14", "0:15:15", "0:15:16", "0:15:17", "0:15:18", "0:15:19",
"0:15:20", "0:15:21", "0:15:22", "0:15:23", "0:15:24", "0:15:25",
"0:15:26", "0:15:27", "0:15:28", "0:15:29", "0:15:30", "0:15:31",
"0:15:32", "0:15:33", "0:15:34", "0:15:35", "0:15:36", "0:15:37",
"0:15:38", "0:15:39", "0:15:40", "0:15:41", "0:15:42", "0:15:43",
"0:15:44", "0:15:45", "0:15:46", "0:15:47", "0:15:48", "0:15:49",
"0:15:50", "0:15:51", "0:15:52", "0:15:53", "0:15:54", "0:15:55",
"0:15:56", "0:15:57", "0:15:58", "0:15:59", "0:16:00", "0:16:01",
"0:16:02", "0:16:03", "0:16:04", "0:16:05", "0:16:06", "0:16:07",
"0:16:08", "0:16:09", "0:16:10", "0:16:11", "0:16:12", "0:16:13",
"0:16:14", "0:16:15", "0:16:16", "0:16:17", "0:16:18", "0:16:19",
"0:16:20", "0:16:21", "0:16:22", "0:16:23", "0:16:24", "0:16:25",
"0:16:26", "0:16:27", "0:16:28", "0:16:29", "0:16:30", "0:16:31",
"0:16:32", "0:16:33", "0:16:34", "0:16:35", "0:16:36", "0:16:37",
"0:16:38", "0:16:39", "0:16:40", "0:16:41", "0:16:42", "0:16:43",
"0:16:44", "0:16:45", "0:16:46", "0:16:47", "0:16:48", "0:16:49",
"0:16:50", "0:16:51", "0:16:52", "0:16:53", "0:16:54", "0:16:55",
"0:16:56", "0:16:57", "0:16:58", "0:16:59", "0:17:00", "0:17:01",
"0:17:02", "0:17:03", "0:17:04", "0:17:05", "0:17:06", "0:17:07",
"0:17:08", "0:17:09", "0:17:10", "0:17:11", "0:17:12", "0:17:13",
"0:17:14", "0:17:15", "0:17:16", "0:17:17", "0:17:18", "0:17:19",
"0:17:20", "0:17:21", "0:17:22", "0:17:23", "0:17:24", "0:17:25",
"0:17:26", "0:17:27", "0:17:28", "0:17:29", "0:17:30", "0:17:31",
"0:17:32", "0:17:33", "0:17:34", "0:17:35", "0:17:36", "0:17:37",
"0:17:38", "0:17:39", "0:17:40", "0:17:41", "0:17:42", "0:17:43",
"0:17:44", "0:17:45", "0:17:46", "0:17:47", "0:17:48", "0:17:49",
"0:17:50", "0:17:51", "0:17:52", "0:17:53", "0:17:54", "0:17:55",
"0:17:56", "0:17:57", "0:17:58", "0:17:59", "0:18:00", "0:18:01",
"0:18:02", "0:18:03", "0:18:04", "0:18:05", "0:18:06", "0:18:07",
"0:18:08", "0:18:09", "0:18:10", "0:18:11", "0:18:12", "0:18:13",
"0:18:14", "0:18:15", "0:18:16", "0:18:17", "0:18:18", "0:18:19",
"0:18:20", "0:18:21", "0:18:22", "0:18:23", "0:18:24", "0:18:25",
"0:18:26", "0:18:27", "0:18:28", "0:18:29", "0:18:30", "0:18:31",
"0:18:32", "0:18:33", "0:18:34", "0:18:35", "0:18:36", "0:18:37",
"0:18:38", "0:18:39", "0:18:40", "0:18:41", "0:18:42", "0:18:43",
"0:18:44", "0:18:45", "0:18:46", "0:18:47", "0:18:48", "0:18:49",
"0:18:50", "0:18:51", "0:18:52", "0:18:53", "0:18:54", "0:18:55",
"0:18:56", "0:18:57", "0:18:58", "0:18:59", "0:19:00", "0:19:01",
"0:19:02", "0:19:03", "0:19:04", "0:19:05", "0:19:06", "0:19:07",
"0:19:08", "0:19:09", "0:19:10", "0:19:11", "0:19:12", "0:19:13",
"0:19:14", "0:19:15", "0:19:16", "0:19:17", "0:19:18", "0:19:19",
"0:19:20", "0:19:21", "0:19:22", "0:19:23", "0:19:24", "0:19:25",
"0:19:26", "0:19:27", "0:19:28", "0:19:29", "0:19:30", "0:19:31",
"0:19:32", "0:19:33", "0:19:34", "0:19:35", "0:19:36", "0:19:37",
"0:19:38", "0:19:39", "0:19:40", "0:19:41", "0:19:42", "0:19:43",
"0:19:44", "0:19:45", "0:19:46", "0:19:47", "0:19:48", "0:19:49",
"0:19:50", "0:19:51", "0:19:52", "0:19:53", "0:19:54", "0:19:55",
"0:19:56", "0:19:57", "0:19:58", "0:19:59", "0:20:00", "0:20:01",
"0:20:02", "0:20:03", "0:20:04", "0:20:05", "0:20:06", "0:20:07",
"0:20:08", "0:20:09", "0:20:10", "0:20:11", "0:20:12", "0:20:13",
"0:20:14", "0:20:15", "0:20:16", "0:20:17", "0:20:18", "0:20:19",
"0:20:20", "0:20:21", "0:20:22", "0:20:23", "0:20:24", "0:20:25",
"0:20:26", "0:20:27", "0:20:28", "0:20:29", "0:20:30", "0:20:31",
"0:20:32", "0:20:33", "0:20:34", "0:20:35", "0:20:36", "0:20:37",
"0:20:38", "0:20:39", "0:20:40", "0:20:41", "0:20:42", "0:20:43",
"0:20:44", "0:20:45", "0:20:46", "0:20:47", "0:20:48", "0:20:49",
"0:20:50", "0:20:51", "0:20:52", "0:20:53", "0:20:54", "0:20:55",
"0:20:56", "0:20:57", "0:20:58", "0:20:59", "0:21:00", "0:21:01",
"0:21:02", "0:21:03", "0:21:04", "0:21:05", "0:21:06", "0:21:07",
"0:21:08", "0:21:09", "0:21:10", "0:21:11", "0:21:12", "0:21:13",
"0:21:14", "0:21:15", "0:21:16", "0:21:17", "0:21:18", "0:21:19",
"0:21:20", "0:21:21", "0:21:22", "0:21:23", "0:21:24", "0:21:25",
"0:21:26", "0:21:27", "0:21:28", "0:21:29", "0:21:30", "0:21:31",
"0:21:32", "0:21:33", "0:21:34", "0:21:35", "0:21:36", "0:21:37",
"0:21:38", "0:21:39", "0:21:40", "0:21:41", "0:21:42", "0:21:43",
"0:21:44", "0:21:45", "0:21:46", "0:21:47", "0:21:48", "0:21:49",
"0:21:50", "0:21:51", "0:21:52", "0:21:53", "0:21:54", "0:21:55",
"0:21:56", "0:21:57", "0:21:58", "0:21:59", "0:22:00", "0:22:01",
"0:22:02", "0:22:03", "0:22:04", "0:22:05", "0:22:06", "0:22:07",
"0:22:08", "0:22:09", "0:22:10", "0:22:11", "0:22:12", "0:22:13",
"0:22:14", "0:22:15", "0:22:16", "0:22:17", "0:22:18", "0:22:19",
"0:22:20", "0:22:21", "0:22:22", "0:22:23", "0:22:24", "0:22:25",
"0:22:26", "0:22:27", "0:22:28", "0:22:29", "0:22:30", "0:22:31",
"0:22:32", "0:22:33", "0:22:34", "0:22:35", "0:22:36", "0:22:37",
"0:22:38", "0:22:39", "0:22:40", "0:22:41", "0:22:42", "0:22:43",
"0:22:44", "0:22:45", "0:22:46", "0:22:47", "0:22:48", "0:22:49",
"0:22:50", "0:22:51", "0:22:52", "0:22:53", "0:22:54", "0:22:55",
"0:22:56", "0:22:57", "0:22:58", "0:22:59", "0:23:00", "0:23:01",
"0:23:02", "0:23:03", "0:23:04", "0:23:05", "0:23:06", "0:23:07",
"0:23:08", "0:23:09", "0:23:10", "0:23:11", "0:23:12", "0:23:13",
"0:23:14", "0:23:15", "0:23:16", "0:23:17", "0:23:18", "0:23:19",
"0:23:20", "0:23:21", "0:23:22", "0:23:23", "0:23:24", "0:23:25",
"0:23:26", "0:23:27", "0:23:28", "0:23:29", "0:23:30", "0:23:31",
"0:23:32", "0:23:33", "0:23:34", "0:23:35", "0:23:36", "0:23:37",
"0:23:38", "0:23:39", "0:23:40", "0:23:41", "0:23:42", "0:23:43",
"0:23:44", "0:23:45", "0:23:46", "0:23:47", "0:23:48", "0:23:49",
"0:23:50", "0:23:51", "0:23:52", "0:23:53", "0:23:54", "0:23:55",
"0:23:56", "0:23:57", "0:23:58", "0:23:59", "0:24:00", "0:24:01",
"0:24:02", "0:24:03", "0:24:04", "0:24:05", "0:24:06", "0:24:07",
"0:24:08", "0:24:09", "0:24:10", "0:24:11", "0:24:12", "0:24:13",
"0:24:14", "0:24:15", "0:24:16", "0:24:17", "0:24:18", "0:24:19",
"0:24:20", "0:24:21", "0:24:22", "0:24:23", "0:24:24", "0:24:25",
"0:24:26", "0:24:27", "0:24:28", "0:24:29", "0:24:30", "0:24:31",
"0:24:32", "0:24:33", "0:24:34", "0:24:35", "0:24:36", "0:24:37",
"0:24:38", "0:24:39", "0:24:40", "0:24:41", "0:24:42", "0:24:43",
"0:24:44", "0:24:45", "0:24:46", "0:24:47", "0:24:48", "0:24:49",
"0:24:50", "0:24:51", "0:24:52", "0:24:53", "0:24:54", "0:24:55",
"0:24:56", "0:24:57", "0:24:58", "0:24:59", "0:25:00", "0:25:01",
"0:25:02", "0:25:03", "0:25:04", "0:25:05", "0:25:06", "0:25:07",
"0:25:08", "0:25:09", "0:25:10", "0:25:11", "0:25:12", "0:25:13",
"0:25:14", "0:25:15", "0:25:16", "0:25:17", "0:25:18", "0:25:19",
"0:25:20", "0:25:21", "0:25:22", "0:25:23", "0:25:24", "0:25:25",
"0:25:26", "0:25:27", "0:25:28", "0:25:29", "0:25:30", "0:25:31",
"0:25:32", "0:25:33", "0:25:34", "0:25:35", "0:25:36", "0:25:37",
"0:25:38", "0:25:39", "0:25:40", "0:25:41", "0:25:42", "0:25:43",
"0:25:44", "0:25:45", "0:25:46", "0:25:47", "0:25:48", "0:25:49",
"0:25:50", "0:25:51", "0:25:52", "0:25:53", "0:25:54", "0:25:55",
"0:25:56", "0:25:57", "0:25:58", "0:25:59", "0:26:00", "0:26:01",
"0:26:02", "0:26:03", "0:26:04", "0:26:05", "0:26:06", "0:26:07",
"0:26:08", "0:26:09", "0:26:10", "0:26:11", "0:26:12", "0:26:13",
"0:26:14", "0:26:15", "0:26:16", "0:26:17", "0:26:18", "0:26:19",
"0:26:20", "0:26:21", "0:26:22", "0:26:23", "0:26:24", "0:26:25",
"0:26:26", "0:26:27", "0:26:28", "0:26:29", "0:26:30", "0:26:31",
"0:26:32", "0:26:33", "0:26:34", "0:26:35", "0:26:36", "0:26:37",
"0:26:38", "0:26:39", "0:26:40", "0:26:41", "0:26:42", "0:26:43",
"0:26:44", "0:26:45", "0:26:46", "0:26:47", "0:26:48", "0:26:49",
"0:26:50", "0:26:51", "0:26:52", "0:26:53", "0:26:54", "0:26:55",
"0:26:56", "0:26:57", "0:26:58", "0:26:59", "0:27:00", "0:27:01",
"0:27:02", "0:27:03", "0:27:04", "0:27:05", "0:27:06", "0:27:07",
"0:27:08", "0:27:09", "0:27:10", "0:27:11", "0:27:12", "0:27:13",
"0:27:14", "0:27:15", "0:27:16", "0:27:17", "0:27:18", "0:27:19",
"0:27:20", "0:27:21", "0:27:22", "0:27:23", "0:27:24", "0:27:25",
"0:27:26", "0:27:27", "0:27:28", "0:27:29", "0:27:30", "0:27:31",
"0:27:32", "0:27:33", "0:27:34", "0:27:35", "0:27:36", "0:27:37",
"0:27:38", "0:27:39", "0:27:40", "0:27:41", "0:27:42", "0:27:43",
"0:27:44", "0:27:45", "0:27:46", "0:27:47", "0:27:48", "0:27:49",
"0:27:50", "0:27:51", "0:27:52", "0:27:53", "0:27:54", "0:27:55",
"0:27:56", "0:27:57", "0:27:58", "0:27:59", "0:28:00", "0:28:01",
"0:28:02", "0:28:03", "0:28:04", "0:28:05", "0:28:06", "0:28:07",
"0:28:08", "0:28:09", "0:28:10", "0:28:11", "0:28:12", "0:28:13",
"0:28:14", "0:28:15", "0:28:16", "0:28:17", "0:28:18", "0:28:19",
"0:28:20", "0:28:21", "0:28:22", "0:28:23", "0:28:24", "0:28:25",
"0:28:26", "0:28:27", "0:28:28", "0:28:29", "0:28:30", "0:28:31",
"0:28:32", "0:28:33", "0:28:34", "0:28:35", "0:28:36", "0:28:37",
"0:28:38", "0:28:39", "0:28:40", "0:28:41", "0:28:42", "0:28:43",
"0:28:44", "0:28:45", "0:28:46", "0:28:47", "0:28:48", "0:28:49",
"0:28:50", "0:28:51", "0:28:52", "0:28:53", "0:28:54", "0:28:55",
"0:28:56", "0:28:57", "0:28:58", "0:28:59", "0:29:00", "0:29:01",
"0:29:02", "0:29:03", "0:29:04", "0:29:05", "0:29:06", "0:29:07",
"0:29:08", "0:29:09", "0:29:10", "0:29:11", "0:29:12", "0:29:13",
"0:29:14", "0:29:15", "0:29:16", "0:29:17", "0:29:18", "0:29:19",
"0:29:20", "0:29:21", "0:29:22", "0:29:23", "0:29:24", "0:29:25",
"0:29:26", "0:29:27", "0:29:28", "0:29:29", "0:29:30", "0:29:31",
"0:29:32", "0:29:33", "0:29:34", "0:29:35", "0:29:36", "0:29:37",
"0:29:38", "0:29:39", "0:29:40", "0:29:41", "0:29:42", "0:29:43",
"0:29:44", "0:29:45", "0:29:46", "0:29:47", "0:29:48", "0:29:49",
"0:29:50", "0:29:51", "0:29:52", "0:29:53", "0:29:54", "0:29:55",
"0:29:56", "0:29:57", "0:29:58", "0:29:59", "0:30:00"), class = "factor"),
student = c("bob", "bob", "bob", "bob"), somemeasure = c(0L,
0L, 1L, 1L)), .Names = c("somedata$Time", "student", "somemeasure"
), row.names = c(NA, 4L), class = "data.frame")
Assuming that your data frame is named df. First, create new column which is POSIXct by pasting together some arbitrary date and original Time column and then converting with as.POSIXct().
Then use function scale_x_datetime() to set breaks and format for labels you want to see.
df$Time2<-as.POSIXct(paste("1960-01-01 ",df$Time))
library(scales)
ggplot(df,aes(Time2,somemeasure))+geom_point()+
scale_x_datetime(breaks=date_breaks("30 sec"),labels = date_format("%M:%S"))

Resources