Question

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))
Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top