Added another example with complete files.
[docutils/kirr.git] / sandbox / docbook / examples / report2 / charts / inbound_2010_2011.R
blob5a111ef9cf67c70bc0e34d58f7be7138018ac8a7
1 rates <- read.csv("../tables/all.csv")
2 title=''
3 x = rates$week
4 y1 = rates$rate.inbound.2010
5 y2 = rates$rate.inbound.2011
6 png(file="inbound_rate_2010_2011.png", width=5, height=3.5, units="in", res=res)
7 xlab.text="week in year"
8 xlab = xlab.text
9 ylab = "units/man hour"
10 if (make.title == T ) top.margin = 3
11 if (make.title != T ) title="" 
12 if (months.grid == T) bottom.margin = 6
13 if (months.grid == T) xlab = ''
14 margins=c(bottom.margin, 4, top.margin, 0.5) 
15 par(mar=margins) 
16 par('family'='serif')
17 plot(x, type='n', xlab=xlab, ylab=ylab, las=1, main=title, ylim=c(range(y1,y2,na.rm=T)), axes=F)
18 axis(1, col=ax_col)
19 axis(2, col=ax_col, las=1, at=axTicks(2))
20 box(col=box_col)
21 abline( h=axTicks(2), lty=1, lwd=lwd_grid, col=ax_col)
22 lines(x,y1,  col=line_colors[1], type="l", lwd=lwd, lty=line_types[1])
23 lines(x,y2, col=line_colors[2],  lwd=lwd, lty=line_types[2])
24 legend("bottomleft", c("2010","2011"), cex=legend_font_size, 
25  col=line_colors,  lty=line_types, bty='y', box.lwd=box.lwd)
26 source("make_x_axis.R")
27 dev.off()
28 t.results <- t.test(y1,y2)
29 m.diff <- mean(y1) - mean(y2)
30 conf.int <- abs(m.diff - t.results$conf.int[1])
31 x1 <- mean(y1)
32 x2 <- mean(y2)
34 percent.diff <- abs((x1 - x2)/((x1 + x2)/2) * 100)
35 # cat("diff in mean is", m.diff, "with +-", conf.int, "and percent change is", percent.diff, "\n")
37 percent.change <- (x2 - x1)/x1 * 100
38 percent.change.low <- ((x2 + conf.int) - x1)/x1 * 100
39 percent.change.high <- ((x2 - conf.int) - x1)/x1 * 100
40 percent.conf.inf <- abs((percent.change.high - percent.change.low) /2)
42 # cat("percent change is", percent.change, "+-", percent.conf.inf, "\n")