1

Consider a data frame df with an extract from a web server access log, with two fields (sample below, duration is in msec and to simplify the example, let's ignore the date).

time,duration
18:17:26.552,8
18:17:26.632,10
18:17:26.681,12
18:17:26.733,4
18:17:26.778,5
18:17:26.832,5
18:17:26.889,4
18:17:26.931,3
18:17:26.991,3
18:17:27.040,5
18:17:27.157,4
18:17:27.209,14
18:17:27.249,4
18:17:27.303,4
18:17:27.356,13
18:17:27.408,13
18:17:27.450,3
18:17:27.506,13
18:17:27.546,3
18:17:27.616,4
18:17:27.664,4
18:17:27.718,3
18:17:27.796,10
18:17:27.856,3
18:17:27.909,3
18:17:27.974,3
18:17:28.029,3

qplot(time, duration, data=df); gives me a graph of the duration. I'd like to add, superimposed a line showing the number of requests for each minute. Ideally, this line would have a single data point per minute, at the :30sec point. If that's too complicated, an acceptable alternative is to have a step line, with the same value (the count of request) during a minute.

One way is to trunc(df$time, units=c("mins")), then calculate the count of request per minute into a new column then graph it.

I'm asking if there is, perhaps, a more direct way to accomplish the above. Thanks.

wishihadabettername
  • 14,231
  • 21
  • 68
  • 85
  • If `time` is in a date-time format, then the `cut` function has methods for date and date-time objects. For example, `df$timeCut = cut(df$time, breaks="min")`. See `?cut.Date` for details. – eipi10 Oct 18 '14 at 05:19
  • Also see [this question](http://stackoverflow.com/questions/17389533/aggregate-values-of-15-minute-steps-to-values-of-hourly-steps) for an approach using the `xts` package that looks more flexible. – eipi10 Oct 18 '14 at 05:24

1 Answers1

1

Following may be helpful. Create a data frame with steps and plot:

           time duration    sec sec2 diffsec2 step30s steps
1  18:17:26.552        8 26.552  552        0       0     0
2  18:17:26.632       10 26.632  632       80       1     1
3  18:17:26.681       12 26.681  681       49       0     0
4  18:17:26.733        4 26.733  733       52       1     1
5  18:17:26.778        5 26.778  778       45       0     0
6  18:17:26.832        5 26.832  832       54       1     1
7  18:17:26.889        4 26.889  889       57       1     2
8  18:17:26.931        3 26.931  931       42       0     0
9  18:17:26.991        3 26.991  991       60       1     1
10 18:17:27.040        5 27.040  040     -951       0     0
11 18:17:27.157        4 27.157  157      117       1     1
12 18:17:27.209       14 27.209  209       52       1     2
13 18:17:27.249        4 27.249  249       40       0     0
14 18:17:27.303        4 27.303  303       54       1     1
15 18:17:27.356       13 27.356  356       53       1     2
16 18:17:27.408       13 27.408  408       52       1     3
17 18:17:27.450        3 27.450  450       42       0     0
18 18:17:27.506       13 27.506  506       56       1     1
19 18:17:27.546        3 27.546  546       40       0     0
20 18:17:27.616        4 27.616  616       70       1     1
21 18:17:27.664        4 27.664  664       48       0     0
22 18:17:27.718        3 27.718  718       54       1     1
23 18:17:27.796       10 27.796  796       78       1     2
24 18:17:27.856        3 27.856  856       60       1     3
25 18:17:27.909        3 27.909  909       53       1     4
26 18:17:27.974        3 27.974  974       65       1     5
27 18:17:28.029        3 28.029  029     -945       0     0
> 
> ggplot(ddf)+geom_point(aes(x=time, y=duration))+geom_line(aes(x=time, y=steps, group=1),color='red')

enter image description here

rnso
  • 23,686
  • 25
  • 112
  • 234