def drawCpuUsage(d,xat,xlbs,pic): data=r.c(d) pch = 22 # point like like a square lty = 1 # line style solid line col = "blue" # line color ltype = "o" # line only http://stat.ethz.ch/R-manual/R-devel/library/graphics/html/plot.html ylim = (0,100) # y domain xaxis=1 yaxis=2 vertical_text=2 horizontal_text=1 text_size=0.8 yat=[x for x in range(0,110,10)] ylbs=["%d%%"%x for x in yat] legend_x=1 legend_y=100 # for r.text method warn_val=40 # val over this value will display a text on point xtext=[idx for idx,val in enumerate(d) if val > warn_val] # text x pos ytext=[val for idx,val in enumerate(d) if val > warn_val] # text y pos labtext=["%d%%"%val for idx,val in enumerate(d) if val > warn_val] # label for text # summary dmax=max(d) sumry="max %.2f%%" % dmax sumrycol="red" if dmax>50 else "green" # plot r.png(pic, width=900,height=450*0.6) r.plot(data, type=ltype, col=col, ylim=ylim, pch=pch, lty=lty, axes=False, ann=False) # draw text that over 40 # http://stat.ethz.ch/R-manual/R-devel/library/graphics/html/text.html r.text(xtext, ytext, labels=labtext, pos=3, cex=0.8, col="red") # summary text r.mtext(sumry, side=3, cex=1, col=sumrycol) # axis r.axis(xaxis, las=vertical_text, at=xat, lab=r.c(xlbs)) r.axis(yaxis, las=horizontal_text, at=yat, lab=r.c(ylbs)) r.box() # titles r.title(main="CPU Sampling") r.title(xlab="Time") r.title(ylab="CPU Usage") # reference line # r.abline(h=50, col="gray") # at 50% # legend r.legend(legend_x, legend_y, r.c(("trunk")), col=col, cex=text_size, pch=pch, lty=lty) r.dev_off()
def test(): data=r.c([1.25,3.45,6.75,20.2,9.9]) # draw image using rpy r.png("test.png", width=300,height=300) r.plot(data, type="o", col="blue", ylim=(0,100), pch=22, lty=1, axes=False, ann=False) r.axis(1, at=(1,2,3,4,5), lab=r.c("a","b","c","d","e")) r.axis(2, las=1, at=(0,50,100)) r.box() r.title(main="CPU usage sampling result") r.title(xlab="Time") r.title(ylab="CPU") r.legend(1,100,r.c("trunk"), cex=0.8, col=r.c("blue"), pch=22, lty=1) r.dev_off()
def MK_fisher_pvalue(win_snp, win_div, AR_snp, AR_div): if win_snp == 0 and win_div == 0 and AR_snp == 0 and AR_div == 0: return 1.0 fisher_result = r.fisher_test(r.matrix(r.c([win_snp, win_div, AR_snp, AR_div]), nr=2)) return fisher_result['p.value']
def plot_one_boxplot_r(values, main="", logstring=""): from rpy import r if values.ndim == 1: v = resize(values, (1, values.size)) else: v = values r.boxplot(v[0,:], xlim=[0,v.shape[0]+1], ylim=r.c(values.min(), values.max()), range=0, log=logstring, main=main) for i in range(1, v.shape[0]): r.boxplot(v[i,:], at=i, add=True, range=0, log=logstring)
def MK_chi_pvalue(win_snp, win_div, AR_snp, AR_div): chi_result = r.chisq_test( r.matrix(r.c([win_snp, win_div, AR_snp, AR_div]), nr=2)) return chi_result['p.value']