-
Notifications
You must be signed in to change notification settings - Fork 0
/
useawk.r
62 lines (50 loc) · 1.54 KB
/
useawk.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
# specify output file and width
#postscript(file="useawk.ps", width=40)
#pdf (file="useawk.pdf",width=40)
# read in two files
mtx1 <- read.table("useawk-d1.data")
mtx2 <- read.table("useawk-d2.data")
#init the arrays to hold the mean values
#we will need 200 slots at most
meanArr1<-rep(NA, 200)
meanArr2<-rep(NA, 200)
# the x label values
x<-rep(NA, 200)
# leave the first spot for 0
x[1] <- 0
for(i in 1:200){
meanArr1[i] <- mean(mtx1[((i-1)*10):(i*10),5])
# i+1 because we left the first slot for 0
x[i+1] = mtx1[i,1]
}
for(i in 1:200){
meanArr2[i] <- mean(mtx2[((i-1)*10):(i*10),5])
}
plot(meanArr1,col="gray", #line colour
xlim=c(0,160),
ylim=c(0,10000),
t="l", # we want a line graph
lwd=1.5, # how thick the line should be
ylab="Number of new terms",
xlab="Number of documents",
xaxt="n", yaxt="n")
# plt the x axis array using x
axis(1, 1:201, x)
# plt the y axis
axis(2)
# make sure the two graphs appear on the same axis
par(new=TRUE)
plot(meanArr2,col="black",
xlim=c(0,160),
ylim=c(0,10000), t="l",
xlab="", # we left these empty because the previous graph has
ylab="", # done them
lwd=1.5,
xaxt="n",
yaxt="n")
axis(1, at=NULL, labels=NA)
axis(2)
# draw the legend
legend("topright", c("Without stemming","With stemming"),
col=c("black", "gray"), lty=c(1,1), lwd="2")
#dev.off() # This is only needed if you use pdf/postscript in interactive mode