0

I'm brand new to R-studio and I could use a little help.

I'm collecting accelerometer data and I need to be able to look at 12 hour files in a meaningful way.

What I would like to do is emulate the picture I posted. Every 100,000 data points I would like the plot to wrap around the same way seismic analysts visual their data.

Sorry I couldn't post a picture because I don't have enough points. here is the link

http://eqinfo.ucsd.edu/cacheimages/vncdumps/orbmonrtd/anza24hr_Z.gif

Data looks like this:

millis,x,y,z
2210,502,533,701
2230,499,538,702
2240,502,535,705
2250,500,560,699

Script to create plot line looks like this

data <- read.csv("LOG_141.DAT", skip=2, header = TRUE,
  stringsAsFactors = FALSE)
str(data)
plot(data$millis[1:100000], data$y[1:100000], type = "l", cex = 0.2, ylim=c(100,1000))
MrFlick
  • 195,160
  • 17
  • 277
  • 295
KeitherB
  • 13
  • 2
  • Please provide sample data using the suggestions at [this question](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Without knowing what your data looks like, it's impossible to offer specific suggestions – MrFlick May 09 '14 at 20:33
  • a little. How large is your full data set? – Ben Bolker May 09 '14 at 20:42
  • The accelerometer starts a new file every 12 hours. at 100 cycles per second that works out to about 4,000,000 data points per file. It varies based on how many ms are missed by the the accelerometer. – KeitherB May 09 '14 at 20:46
  • It's going to be *very* difficult to plot 4 million points without some sort of subsampling, at least in R. – Ben Bolker May 09 '14 at 20:53
  • I can make the files whatever size is necessary. its not hard to make the Arduino create a new file at a certain time stamp. the script I have works for processing the data I have. It works with 6 files and over 100 million points no problem. If its necessary to shorten the time of each file in order to do stacking so be it. I don't believe the size of my data files should have anything to do with pointing me in the right direction or giving me real suggestions. – KeitherB May 22 '14 at 00:35
  • Didn't I give you a real suggestion below? I was trying to give you an answer that would be useful within the stated terms of your problem, and to suggest that simply trying to plot the full data set wasn't going to work very well in R. – Ben Bolker May 22 '14 at 17:33

1 Answers1

0

Make up data:

d <- data.frame(millis=1:1e6,y=rnorm(1e6))
d$c <- rep(1:1e5,length.out=nrow(d))

This is easy to write but takes a long time to render.

library(ggplot2)
ggplot(d,aes(x=millis,y=y))+facet_grid(c~.)+geom_line()

Or (also slow)

library(lattice)
xyplot(y~millis|c,data=d,layout=c(10,1))

(To be honest I gave up waiting for either of the above to finish.)

Fastest in base graphics:

par(mfrow=c(10,1),mar=c(0,4,0,1),las=1)
for (i in 1:10) {
    plot(y~millis,data=d[1:999999+(i-1)*1e5,],type="l",
         axes=FALSE,ann=FALSE)
    box()
    axis(side=2)
}

See ?par for help adjusting outer margins, etc etc etc.

You might consider subsampling: if your screen (or other output device) is only a few 1000 pixels wide, and you plot 100,000 points across the width of the screen, then most of them are going to be hidden anyway!

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • 1
    did you run all of the R code in my answer?? I wouldn't really recommend the first two approaches -- try the last one first. If you want to use this code with your data described above, you'll need to substitute `data` for `d`. – Ben Bolker May 09 '14 at 21:16
  • Thanks. a few tweeks and this is what I cam up with. Its working well now. par(mfrow=c(12,1),mar=c(0,4,.5,1), oma = c(1,2,1,1), las=1) for (i in 0:11) { plot(y~millis,data=Accelerometer[(300000*i+1):(300000*i+300000),], type="l", ylim=c(400,600), axes=FALSE,ann=FALSE) box() axis(side=2) } – KeitherB May 09 '14 at 21:33
  • Why did I get a negative reputation point for asking a question that had an answer? – KeitherB May 22 '14 at 17:17