-
Notifications
You must be signed in to change notification settings - Fork 354
/
Copy pathanalyze_fadein.r
executable file
·69 lines (63 loc) · 2 KB
/
analyze_fadein.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env Rscript
library('getopt');
library('lattice');
# 0=no param, 1=required, 2=optional
spec <- matrix( c(
'help', 'h', 0, "logical", "print help message",
'file', 'f', 2, "character", "path to filename to read, defaults to STDIN",
'output', 'o', 2, "character", "path to filename to write to, defaults to 'graph.png'",
'sep', 's', 2, "character", "CSV separator, default to ','",
'title', 't', 2, "character", "Title for the graph 'Test'"),
byrow=T, ncol=5
)
opt <- getopt(spec);
## --help
if ( !is.null(opt$help) ) {
self = commandArgs()[1];
cat(paste("Usage: ",self," [--help|-h] [--file|-f <path>] [--output|-o <path>] [--sep|-s <char>] [--title|-t <string>]\n", sep=""));
q(status=1);
}
## input - STDIN or file
if (is.null(opt$file)) {
print("read from STDIN")
con <- file(description="stdin",open="r")
} else {
con <- file(opt$file,open="r")
}
## output - STDOUT or file
if (is.null(opt$output)) {
out <- "/dev/stdout"
} else {
out <- opt$output
}
## sep
if (is.null(opt$sep)) {
opt$sep <- ","
}
## title
if (is.null(opt$title)) {
title <- paste("Test", opt$output)
} else {
title <- opt$title
}
## set that we write to png file
png(out)
datWithT <- read.csv(con, sep=opt$sep)
dat <- datWithT[,-1]
## hack to parameterize formula
## we have to create c(a,b,c,d,e,f) where a,b,..,f depend on the read CSV we don't know yet
strFactor <- paste(
"c(",
paste(names(dat), collapse=","),
")",
collapse=" ", sep="")
## create the formula c(a,b,c,d,e,f) ~ c(1:nrow(dat))
f <- eval(parse(text=strFactor)) ~ c(1:nrow(dat))
colors <- c("blue", "green", "red", "black", "magenta", "yellow", "cyan")
xyplot(f,
data=dat,
xlab="iterations", ylab="hits", ylim=c(0, max(dat)+200), between=list(x=0,y=100),
key=list(space="bottom",
points=list(col=head(colors, n=ncol(dat)), pch=1),
text=list(names(dat)), cex=0.6),
main=title, col=rep(colors, each=nrow(dat)))