Axis x minute by minute

Asked

Viewed 543 times

-1

I need to identify and quantify time intervals greater than 5 minutes in a long column. "Time" column. The following dput:

structure(list(Time = structure(c(1541062677, 1541062678, 1541062680, 
1541062681, 1541062681, 1541062683, 1541062685, 1541062686, 1541062688, 
1541062688), class = c("POSIXct", "POSIXt"), tzone = ""), CIDM = 
c(0.12146956236827, 
0.24293912473654, 0.337352282020179, 0.431765439303817, 0.553235001672087, 
0.674704564040357, 0.769117721323995, 0.863530878607634, 0.985000440975904, 
1.10647000334417)), .Names = c("Time", "CIDM"), row.names = 142320:142329, 
class = "data.frame")
  • 2

    No occurrence of the column Time placed above has more than 5 minutes of difference from the others. In addition, the question is too open. Take, for example, the times 12:00, 12:06, 12:12, 12:14, 12:19. What is the expected response to a case like this?

  • 1

    @The differences don’t even reach 5 seconds.

  • With the same dice game how can I make to appear mmenuto the minute? When plotting the entire dice game appears every two hours. I would like it to appear minute by minute on the X. Plot axis (CIDM~Time,type="l",data = CI)

  • @Júlioazambuja, edit your question to include the information on that last comment.

1 answer

4

First an example with a time line longer than five minutes:

set.seed(321)
CI <- data.frame(
  Time = as.POSIXct(sort(sample(1541062677:1541063688, 10)), origin = '1970-01-01 00:00.00 UTC'),
  CIDM = c(0.12146956236827, 0.24293912473654, 0.337352282020179, 0.431765439303817, 0.553235001672087, 0.674704564040357, 0.769117721323995, 0.863530878607634, 0.985000440975904, 1.10647000334417)
)

The POSIX class is defined as the number of seconds from a reference date (January 1, 1970 by default); so it appears as whole numbers when dput wheel. Identifying lines with an interval greater than five minutes is simple using diff:

> CI[diff(CI$Time) > 5*60, ]
                Time      CIDM
7 2018-11-01 10:05:32 0.7691177

That is, the interval between lines 7 and 8 is more than five minutes.

For a good control of the display of dates and times in graphs, the most practical is to use ggplot2 and scales:

library(ggplot2)
library(scales)

ggplot(CI, aes(Time, CIDM)) +
  geom_line() + geom_point() +
  scale_x_datetime(minor_breaks = date_breaks("5 min"), date_labels = '%M:%S')

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.