Time series with 10 minute frequency in R using the ts() function

Hey, I have this data where I have data entries every 10 minutes apart with a cycle of 24hrs from 2019-01-01 00:00:00 to 2022-07-09 23:50:00. I want to use ts function but the time plot for the data is coming out wrong. Any assistance will be highly appreciated.

below is the sample from one day:

Data:

structure(list(Date = structure(c(1546300800, 1546301400, 1546302000, 
1546302600, 1546303200, 1546303800, 1546304400, 1546305000, 1546305600, 
1546306200, 1546306800, 1546307400, 1546308000, 1546308600, 1546309200, 
1546309800, 1546310400, 1546311000, 1546311600, 1546312200, 1546312800, 
1546313400, 1546314000, 1546314600, 1546315200, 1546315800, 1546316400, 
1546317000, 1546317600, 1546318200, 1546318800, 1546319400, 1546320000, 
1546320600, 1546321200, 1546321800, 1546322400, 1546323000, 1546323600, 
1546324200, 1546324800, 1546325400, 1546326000, 1546326600, 1546327200, 
1546327800, 1546328400, 1546329000, 1546329600, 1546330200, 1546330800, 
1546331400, 1546332000, 1546332600, 1546333200, 1546333800, 1546334400, 
1546335000, 1546335600, 1546336200, 1546336800, 1546337400, 1546338000, 
1546338600, 1546339200, 1546339800, 1546340400, 1546341000, 1546341600, 
1546342200, 1546342800, 1546343400, 1546344000, 1546344600, 1546345200, 
1546345800, 1546346400, 1546347000, 1546347600, 1546348200, 1546348800, 
1546349400, 1546350000, 1546350600, 1546351200, 1546351800, 1546352400, 
1546353000, 1546353600, 1546354200, 1546354800, 1546355400, 1546356000, 
1546356600, 1546357200, 1546357800, 1546358400, 1546359000, 1546359600, 
1546360200, 1546360800, 1546361400, 1546362000, 1546362600, 1546363200, 
1546363800, 1546364400, 1546365000, 1546365600, 1546366200, 1546366800, 
1546367400, 1546368000, 1546368600, 1546369200, 1546369800, 1546370400, 
1546371000, 1546371600, 1546372200, 1546372800, 1546373400, 1546374000, 
1546374600, 1546375200, 1546375800, 1546376400, 1546377000, 1546377600, 
1546378200, 1546378800, 1546379400, 1546380000, 1546380600, 1546381200, 
1546381800, 1546382400, 1546383000, 1546383600, 1546384200, 1546384800, 
1546385400, 1546386000, 1546386600), tzone = "UTC", class = c("POSIXct", 
"POSIXt")), ASA296PDI893 = c(58.7, 58.34, 58.34, 58.56, 58.74, 
58.74, 58.34, 58.74, 58.74, 58.59, 58.74, 58.74, 58.74, 58.06, 
57.95, 57.95, 57.95, 57.95, 58.34, 58.1, 57.95, 58.34, 58.14, 
57.66, 57.95, 57.87, 57.7, 57.95, 57.95, 57.79, 57.95, 57.95, 
57.95, 57.95, 57.95, 57.95, 57.95, 57.95, 57.95, 57.95, 57.82, 
57.55, 57.95, 57.95, 57.95, 57.35, 57.55, 57.55, 57.55, 57.22, 
57.55, 57.55, 57.55, 67.07, 67.07, 67.07, 67.33, 67.87, 67.87, 
68.22, 69.06, 69.06, 68.69, 69.06, 69.85, 69.85, 69.97, 71.04, 
70.5, 60.89, 60.72, 61.44, 62.31, 62.14, 61.92, 61.92, 62.31, 
62.31, 62.31, 62.31, 62.31, 62.61, 63.5, 71.69, 72.89, 73.82, 
73.43, 72.13, 71.84, 73.03, 72.6, 72.54, 73.03, 72.45, 71.84, 
71.46, 71.84, 71.84, 69.96, 62.71, 62.71, 62.41, 62.71, 62.71, 
62.71, 62.71, 62.71, 62.71, 62.31, 62.31, 62.31, 62.31, 61.92, 
61.99, 62.31, 62.01, 61.92, 62.31, 61.9, 62.31, 62.57, 62.71, 
63.66, 63.9, 63.57, 73.43, 73.43, 72.5, 71.84, 71.04, 70.25, 
70.04, 69.85, 69.85, 69.85, 69.85, 69.51, 69.46, 69.85, 69.85, 
68.28, 61.12, 61.12, 60.89)), row.names = c(NA, -144L), class = c("tbl_df", 
"tbl", "data.frame"))```

Code: TS <- ts(sample[,2], start = c(2019,01,01))

Time Plot:

x-axis easier fiddled with by {fpp3} package, which produces {ggplot2} object

input <- structure(list(Date = structure(c(
  1546300800, 1546301400, 1546302000,
  1546302600, 1546303200, 1546303800, 1546304400, 1546305000, 1546305600,
  1546306200, 1546306800, 1546307400, 1546308000, 1546308600, 1546309200,
  1546309800, 1546310400, 1546311000, 1546311600, 1546312200, 1546312800,
  1546313400, 1546314000, 1546314600, 1546315200, 1546315800, 1546316400,
  1546317000, 1546317600, 1546318200, 1546318800, 1546319400, 1546320000,
  1546320600, 1546321200, 1546321800, 1546322400, 1546323000, 1546323600,
  1546324200, 1546324800, 1546325400, 1546326000, 1546326600, 1546327200,
  1546327800, 1546328400, 1546329000, 1546329600, 1546330200, 1546330800,
  1546331400, 1546332000, 1546332600, 1546333200, 1546333800, 1546334400,
  1546335000, 1546335600, 1546336200, 1546336800, 1546337400, 1546338000,
  1546338600, 1546339200, 1546339800, 1546340400, 1546341000, 1546341600,
  1546342200, 1546342800, 1546343400, 1546344000, 1546344600, 1546345200,
  1546345800, 1546346400, 1546347000, 1546347600, 1546348200, 1546348800,
  1546349400, 1546350000, 1546350600, 1546351200, 1546351800, 1546352400,
  1546353000, 1546353600, 1546354200, 1546354800, 1546355400, 1546356000,
  1546356600, 1546357200, 1546357800, 1546358400, 1546359000, 1546359600,
  1546360200, 1546360800, 1546361400, 1546362000, 1546362600, 1546363200,
  1546363800, 1546364400, 1546365000, 1546365600, 1546366200, 1546366800,
  1546367400, 1546368000, 1546368600, 1546369200, 1546369800, 1546370400,
  1546371000, 1546371600, 1546372200, 1546372800, 1546373400, 1546374000,
  1546374600, 1546375200, 1546375800, 1546376400, 1546377000, 1546377600,
  1546378200, 1546378800, 1546379400, 1546380000, 1546380600, 1546381200,
  1546381800, 1546382400, 1546383000, 1546383600, 1546384200, 1546384800,
  1546385400, 1546386000, 1546386600
), tzone = "UTC", class = c(
  "POSIXct",
  "POSIXt"
)), ASA296PDI893 = c(
  58.7, 58.34, 58.34, 58.56, 58.74,
  58.74, 58.34, 58.74, 58.74, 58.59, 58.74, 58.74, 58.74, 58.06,
  57.95, 57.95, 57.95, 57.95, 58.34, 58.1, 57.95, 58.34, 58.14,
  57.66, 57.95, 57.87, 57.7, 57.95, 57.95, 57.79, 57.95, 57.95,
  57.95, 57.95, 57.95, 57.95, 57.95, 57.95, 57.95, 57.95, 57.82,
  57.55, 57.95, 57.95, 57.95, 57.35, 57.55, 57.55, 57.55, 57.22,
  57.55, 57.55, 57.55, 67.07, 67.07, 67.07, 67.33, 67.87, 67.87,
  68.22, 69.06, 69.06, 68.69, 69.06, 69.85, 69.85, 69.97, 71.04,
  70.5, 60.89, 60.72, 61.44, 62.31, 62.14, 61.92, 61.92, 62.31,
  62.31, 62.31, 62.31, 62.31, 62.61, 63.5, 71.69, 72.89, 73.82,
  73.43, 72.13, 71.84, 73.03, 72.6, 72.54, 73.03, 72.45, 71.84,
  71.46, 71.84, 71.84, 69.96, 62.71, 62.71, 62.41, 62.71, 62.71,
  62.71, 62.71, 62.71, 62.71, 62.31, 62.31, 62.31, 62.31, 61.92,
  61.99, 62.31, 62.01, 61.92, 62.31, 61.9, 62.31, 62.57, 62.71,
  63.66, 63.9, 63.57, 73.43, 73.43, 72.5, 71.84, 71.04, 70.25,
  70.04, 69.85, 69.85, 69.85, 69.85, 69.51, 69.46, 69.85, 69.85,
  68.28, 61.12, 61.12, 60.89
)), row.names = c(NA, -144L), class = c(
  "tbl_df",
  "tbl", "data.frame"
))

input <- input[2]
# if not using tsibble,
# don't put dates in the data; that's what start is for
TS <- ts(input, start = c(2019,01,01), frequency = 144)
plot(TS)

1 Like

I never work with time series and I rarely use the base plotting function, so this may be the silliest possible solution to the problem. I was working on it when @technocrat posted his better solution.

sample <- structure(list
                (Date = structure(c(1546300800, 1546301400, 1546302000, 
                                    1546302600, 1546303200, 1546303800, 1546304400, 1546305000, 1546305600, 
                                    1546306200, 1546306800, 1546307400, 1546308000, 1546308600, 1546309200, 
                                    1546309800, 1546310400, 1546311000, 1546311600, 1546312200, 1546312800, 
                                    1546313400, 1546314000, 1546314600, 1546315200, 1546315800, 1546316400, 
                                    1546317000, 1546317600, 1546318200, 1546318800, 1546319400, 1546320000, 
                                    1546320600, 1546321200, 1546321800, 1546322400, 1546323000, 1546323600, 
                                    1546324200, 1546324800, 1546325400, 1546326000, 1546326600, 1546327200, 
                                    1546327800, 1546328400, 1546329000, 1546329600, 1546330200, 1546330800, 
                                    1546331400, 1546332000, 1546332600, 1546333200, 1546333800, 1546334400, 
                                    1546335000, 1546335600, 1546336200, 1546336800, 1546337400, 1546338000, 
                                    1546338600, 1546339200, 1546339800, 1546340400, 1546341000, 1546341600, 
                                    1546342200, 1546342800, 1546343400, 1546344000, 1546344600, 1546345200, 
                                    1546345800, 1546346400, 1546347000, 1546347600, 1546348200, 1546348800, 
                                    1546349400, 1546350000, 1546350600, 1546351200, 1546351800, 1546352400, 
                                    1546353000, 1546353600, 1546354200, 1546354800, 1546355400, 1546356000, 
                                    1546356600, 1546357200, 1546357800, 1546358400, 1546359000, 1546359600, 
                                    1546360200, 1546360800, 1546361400, 1546362000, 1546362600, 1546363200, 
                                    1546363800, 1546364400, 1546365000, 1546365600, 1546366200, 1546366800, 
                                    1546367400, 1546368000, 1546368600, 1546369200, 1546369800, 1546370400, 
                                    1546371000, 1546371600, 1546372200, 1546372800, 1546373400, 1546374000, 
                                    1546374600, 1546375200, 1546375800, 1546376400, 1546377000, 1546377600, 
                                    1546378200, 1546378800, 1546379400, 1546380000, 1546380600, 1546381200, 
                                    1546381800, 1546382400, 1546383000, 1546383600, 1546384200, 1546384800, 
                                    1546385400, 1546386000, 1546386600), tzone = "UTC", class = c("POSIXct", "POSIXt")), 
                  ASA296PDI893 = c(58.7, 58.34, 58.34, 58.56, 58.74, 
                                   58.74, 58.34, 58.74, 58.74, 58.59, 58.74, 58.74, 58.74, 58.06, 
                                   57.95, 57.95, 57.95, 57.95, 58.34, 58.1, 57.95, 58.34, 58.14, 
                                   57.66, 57.95, 57.87, 57.7, 57.95, 57.95, 57.79, 57.95, 57.95, 
                                   57.95, 57.95, 57.95, 57.95, 57.95, 57.95, 57.95, 57.95, 57.82, 
                                   57.55, 57.95, 57.95, 57.95, 57.35, 57.55, 57.55, 57.55, 57.22, 
                                   57.55, 57.55, 57.55, 67.07, 67.07, 67.07, 67.33, 67.87, 67.87, 
                                   68.22, 69.06, 69.06, 68.69, 69.06, 69.85, 69.85, 69.97, 71.04, 
                                   70.5, 60.89, 60.72, 61.44, 62.31, 62.14, 61.92, 61.92, 62.31, 
                                   62.31, 62.31, 62.31, 62.31, 62.61, 63.5, 71.69, 72.89, 73.82, 
                                   73.43, 72.13, 71.84, 73.03, 72.6, 72.54, 73.03, 72.45, 71.84, 
                                   71.46, 71.84, 71.84, 69.96, 62.71, 62.71, 62.41, 62.71, 62.71, 
                                   62.71, 62.71, 62.71, 62.71, 62.31, 62.31, 62.31, 62.31, 61.92, 
                                   61.99, 62.31, 62.01, 61.92, 62.31, 61.9, 62.31, 62.57, 62.71, 
                                   63.66, 63.9, 63.57, 73.43, 73.43, 72.5, 71.84, 71.04, 70.25, 
                                   70.04, 69.85, 69.85, 69.85, 69.85, 69.51, 69.46, 69.85, 69.85, 
                                   68.28, 61.12, 61.12, 60.89)), row.names = c(NA, -144L), 
                class = c("tbl_df", "tbl", "data.frame"))
#TS <- ts(sample[,2], start = sample[1,1],end = sample(144,1),frequency = 144)

TS <- ts(sample[,2], start = sample[1,1],frequency = 1/600)
TICKS <- lubridate::ymd_hms(c("2019-01-01 00:00:00","2019-01-01 06:00:00",
                     "2019-01-01 12:00:00","2019-01-01 18:00:00",
                     "2019-01-02 00:00:00"))
plot(TS,axes = FALSE)
axis(side = 1,at = TICKS,labels = c("00:00","06:00","12:00",
                                    "18:00","00:00"))
axis(side = 2)
box()

Created on 2022-09-11 with reprex v2.0.2

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.