0
$\begingroup$

I have a two-dimensional data set that looks like $(t, x)$ where $t$ is a time in seconds when event $X$ happened. $X$ ranges from $[0, 200]$.

I want to visualize the frequency of each $x$ at time $t$ over some time period. I guess this would be a bar graph with $x$-axis being event #, $y$-axis being frequency, and $z$-axis being time, $t$.

Furthermore, I would like to group all events that happen within say a 5 second interval to count towards the same frequency bar on the $y$-axis.

If there is a way to do this with R that would be even better.

My goal is to get a sense how often some event occurs over the course of a day, and when certain events happen a lot or infrequently. If you know of a better way to understand this information, I am all ears.

$\endgroup$
2
  • 2
    $\begingroup$ It might help if you showed us some data (invented if necessary) which illustrates your question. $\endgroup$
    – Henry
    May 11, 2011 at 20:18
  • $\begingroup$ @Henry that is actually exactly what the data looks like: (1, 3), (1, 4), (2.4, 4), ... where x is time in seconds and the y coordinate is [0,200] $\endgroup$ May 11, 2011 at 20:25

1 Answer 1

1
$\begingroup$

The key thing is you "want to visualize the frequency of each X at time t over some time period.". Here is a starter with the straightforward methods. Which method to use will very much depend on how your actual data looks.

# generate data
n <- 10000
mydata <- data.frame(
    Time=rexp(n, 5),
    X=runif(n))

First method - straightforward point plot, using transparency to avoid over-plotting problems

library(ggplot2)
ggplot(mydata, aes(x=Time, y=X)) +
    geom_point(alpha=0.1)

enter image description here

Second method - turn Time into a discrete variable and show box plots

mydata$Time.f <- cut(mydata$Time, breaks=20)
ggplot(mydata, aes(x=Time.f, y=X)) +
    geom_boxplot() +
    coord_flip()

enter image description here

$\endgroup$
1
  • $\begingroup$ I think he wants 5 sec. binning. I also assume his X are integral and hence each X could get its own count over every 5 sec interval. $\endgroup$ Mar 20, 2013 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.