rm(list=ls()) parlaments=read.csv("parlaments.csv") parlaments$pop=parlaments$population/1000000 parlaments$power=round(100/parlaments$parlament_size, 2) parlaments$reps=round(parlaments$population/parlaments$parlament_size)/1000 cor(parlaments$reps, parlaments$power) # 0.914 colors=c("chartreuse", "black", "red") popcuts=data.frame(low=c(0, 9, 11), high=c(9, 11, 999)) jpeg("parlaments.jpeg", width = 6, height = 6, units = 'in', res = 500) plot(c(0,1.5), c(0, 150), axes=FALSE, type="n", xlab="MP political power (%)", ylab="Represented population (thousands)", main="", cex.main=1) axis(1, 0.5*(0:3),cex.axis=0.8) axis(2,at=50*(0:3), las=1, cex.axis=0.8) lines(c(0,1.5), c(50,50), lty=2, col="black") lines(c(0,1.5), c(100,100), lty=2, col="black") lines(c(0.5, 0.5), c(0,150), lty=2, col="black") lines(c(1, 1), c(0,150), lty=2, col="black") for(j in 1:3){ w=which(between(parlaments$pop, popcuts$low[j], popcuts$high[j])) pt=parlaments[w,] points(pt$power, pt$reps, col=colors[j], pch=16, cex=1.5) print(paste("j=", j, " cor=", cor(pt$reps, pt$power), sep="")) } w=which(parlaments$State=="Israel") pt=parlaments[w,] points(pt$power, pt$reps, col="blue", pch=16, cex=1.5) w=which(parlaments$reps>=100 | parlaments$power>=1) pt=parlaments[w,] text(x=pt$power, y=pt$reps, labels=pt$State, pos=4, cex=1) w=which(parlaments$reps<50 & parlaments$power<0.5) pt=parlaments[w,] text(x=pt$power, y=pt$reps, labels=pt$State, pos=2, cex=1) legend(x="top", ncol=3, title="Population (Millions)", fill=colors, legend=c("7-9", "9-11", "11-13"), cex=0.8, inset=0.01, box.col='white') dev.off()