
Untitled
By: a guest on
May 2nd, 2012 | syntax:
None | size: 2.36 KB | hits: 12 | expires: Never
library(lattice)
day <- c("110513")
directions <- c("0", "180", "L45", "L90", "L135", "R45", "R90", "R135")
direction.n <- length(directions)
wave.names <- paste("w.", directions, sep="")
for (d in directions) {
x <- read.csv(paste(day, "-1-a-", d, "_proc-wave.csv", sep=""),
skip=10, header=T)
assign(paste("w.", d, sep=""), x)
}
roi.n <- dim(x)[2] - 2 # minus time column and extra X column, it depends on csv files
my.reshape <- function(){
w.ret <- data.frame()
for (i in wave.names) {
w.n <- get(i)[, -dim(x)[2]] # remove the extra X column
for (j in 1:roi.n) {
w.ret <- rbind(w.ret,
data.frame(time=w.n$time,
value=w.n[,j+1],
direction=i,
roi=j))
}
}
return(w.ret)
}
plot.for.roi <- function(w=w.ret){
roi.plot <- xyplot(-value ~ time | roi, group=direction, w, type="l")
pdf(file="plot.for.roi.pdf")
print(roi.plot)
dev.off()
print(roi.plot)
}
plot.for.direction <- function(w=w.ret){
direction.plot <- xyplot(-value ~ time | direction, group=roi, w, type="l")
pdf(file="plot.for.direction.pdf")
print(direction.plot)
dev.off()
print(direction.plot)
}
my.f <- function(){
source("wave.plot.r")
}
## USAGE
## > source("wave.plot.r")
## > ls()
## [1] "d" "day" "direction.n"
## [4] "directions" "my.f" "my.reshape"
## [7] "plot.for.direction" "plot.for.roi" "roi.n"
## [10] "w.0" "w.180" "w.L135"
## [13] "w.L45" "w.L90" "w.R135"
## [16] "w.R45" "w.R90" "wave.names"
## [19] "x"
## > w <- my.reshape()
## > head(w)
## time value direction roi
## 1 0 0.848247 w.0 1
## 2 30 0.848247 w.0 1
## 3 60 1.853140 w.0 1
## 4 90 -0.403139 w.0 1
## 5 120 -0.262454 w.0 1
## 6 150 -0.573379 w.0 1
## > str(w)
## 'data.frame': 3960 obs. of 4 variables:
## $ time : num 0 30 60 90 120 150 180 210 240 270 ...
## $ value : num 0.848 0.848 1.853 -0.403 -0.262 ...
## $ direction: Factor w/ 8 levels "w.0","w.180",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ roi : int 1 1 1 1 1 1 1 1 1 1 ...
## > plot.for.roi(w)
## > plot.for.direction(w)