inputFile="GSM_T10_DENSTY_WHTR_C0_DEGREES.txt"; a=read.csv(file=inputFile,header=TRUE,sep="\t") datasetName=strsplit(inputFile,"[.]")[[1]][1] datasetName=strsplit(datasetName ,"[/]") datasetName=datasetName[[1]][length(datasetName[[1]])] datasetName="1-C GSM-Density networks" k=kruskal.test(FREQ~RING,data=a) print(k) # start plotting with the city with highest frequency # to make plotting nicer. # max_freq=max(a$FREQ) max_degree=max(a$DEGREE) max_city=a[ a$FREQ ==max_freq,3]; # make RING categorical variable a$RING<-factor(a$RING); city_list=levels(a$RING); plot_colors <- c( rgb(r=0.0,g=0.0,b=0.9) ,rgb(r=0.0,g=0.9,b=0.0) ,rgb(r=0.0,g=0.9,b=0.9) ,rgb(r=0.9,g=0.0,b=0.0) ,rgb(r=0.9,g=0.0,b=0.9) ,rgb(r=0.9,g=0.9,b=0.0) ,rgb(r=0.9,g=0.9,b=0.9) ,rgb(r=0.6,g=0.3,b=0.0) ,rgb(r=0.3,g=0.6,b=0.9) ,rgb(r=0.9,g=0.6,b=0.3) ,"yellow","blue", "red", "forestgreen","magenta" ) plot_colors_index=1; isFirts=TRUE; for (city in city_list){ city_total_freq= sum(a[ a$RING ==city,2]); x=a[ a$RING ==city,1]; y=a[ a$RING ==city,2]; y=a[ a$RING ==city,2]/city_total_freq; max_freq=1; ds<-data.frame(x=x,y=y) #, ylim=c(0,max_freq) if(isFirts) # plot(ds, main = paste("Degree distribution for",datasetName),xlab = "degree", ylab = "pdf of frequency",log="xy", type="l",xlim=c(1,max_degree) plot(ds, xlab = "degree", ylab = "pdf of frequency",log="xy", type="l",xlim=c(1,max_degree) #, ylim=c(1,max_freq) ,lty = plot_colors_index, lwd=2,col = plot_colors[plot_colors_index]) else lines(ds,lty = plot_colors_index, lwd=2,col = plot_colors[plot_colors_index]) plot_colors_index=plot_colors_index+1; isFirts = FALSE; } legend("bottomleft", city_list, cex=0.8, col=plot_colors, lty=1:plot_colors_index, lwd=2, bty="n"); ## plot statistics on plot rp = vector('expression',3) #rp[1] = substitute(expression(MYVALUE), # list(MYVALUE = k$method))[2] rp[1] = substitute(expression(italic("chi-squared") == MYOTHERVALUE2), list(MYOTHERVALUE2 = format(k$statistic, digits = 4)))[2] rp[2] = substitute(expression(italic(df) == MYOTHERVALUE), list(MYOTHERVALUE = format(k$parameter, digits = 4)))[2] rp[3] = substitute(expression(italic(p.value) == MYOTHERVALUE), list(MYOTHERVALUE = format(k$p.value, digits = 4)))[2] legend('topright', legend = rp, bty = 'n') for (city in city_list){ city_total_freq= sum(a[ a$RING ==city,2]); print(city) print(city_total_freq) } dev.copy(pdf,paste('results/',datasetName,'.pdf',sep='')); dev.off()