Added another example with complete files.
[docutils/kirr.git] / sandbox / docbook / examples / report2 / charts / return_2010_2011.R
blob884d1d64c5d72ace2cfbf652263fb74e2d9be7d4
1 rates <- read.csv("../tables/all.csv")
2 x = rates$week
3 title='Return Rates, 2010, 2011'
4 y1 = rates$rate.returns.2010
5 y2 = rates$rate.returns.2011
6 png(file="return_rate_2010_2011.png", width=5, height=3.5, units="in", res=res)
7 xlab = "Week in Year"
8 xlab.text = xlab
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 y_range = range(y1, y2, na.rm=T)
18 plot(x, type='n', xlab=xlab, ylab=ylab, las=1, main=title, ylim=c(range(y1,y2,na.rm=T)), axes=F)
19 axis(1, col=ax_col)
20 axis(2, col=ax_col, las=1, at=axTicks(2))
21 box(col=box_col)
22 abline( h=axTicks(2), lty=1, lwd=lwd_grid, col=ax_col)
23 lines(x,y1,  col=line_colors[1], type="l", lwd=lwd, lty=line_types[1])
24 lines(x,y2, col=line_colors[2], lwd=lwd, lty=line_types[2])
25 error_bars = predict(lm(y1[20:40]~x[20:40]), interval='confidence')
26 #segments(20,error_bars[1], 40, error_bars[20], col=line_colors[1])
27 error_bars = predict(lm(y2[20:40]~x[20:40]), interval='confidence')
28 #segments(20,error_bars[1], 40, error_bars[20], col=line_colors[2])
29 legend("bottomleft", c("2010","2011"), cex=legend_font_size, 
30  col=line_colors,  lty=line_types, bty='y', box.lwd=box.lwd)
31 source("make_x_axis.R")
32 dev.off()
33 t.results <- t.test(y1,y2)
34 m.diff <- mean(y1) - mean(y2)
35 conf.int <- abs(m.diff - t.results$conf.int[1])
36 x1 <- mean(y1)
37 x2 <- mean(y2)
39 percent.diff <- abs((x1 - x2)/((x1 + x2)/2) * 100)
40 # cat("diff in mean is", m.diff, "with +-", conf.int, "and percent change is", percent.diff, "\n")
42 percent.change <- (x2 - x1)/x1 * 100
43 percent.change.low <- ((x2 + conf.int) - x1)/x1 * 100
44 percent.change.high <- ((x2 - conf.int) - x1)/x1 * 100
46 percent.conf.int <- abs((percent.change.high - percent.change.low)/2)
48 # cat("percent change is", percent.change, "+-", percent.conf.int,  "\n")