mypar<-function(a=1,b=1,brewer.n=8,brewer.name="Dark2",...){ par(mar=c(2.5,2.5,1.6,1.1),mgp=c(1.5,.5,0)) par(mfrow=c(a,b),...) palette(brewer.pal(brewer.n,brewer.name)) } dat=read.table("http://rafalab.jhsph.edu/simplystats/nba.txt",header=FALSE) examples=dat[dat[,3]=="e",] dat=dat[dat[,3]=="a",] dat=dat[order(-dat[,2]),] dat[,2]=dat[,2]*100 bitmap("kobe.png",res=600,width=5,height=5) plot(dat[,2],type="n",xlab="rank",ylab="Career FG%",cex.lab=1.35) text(1:nrow(dat),dat[,2],dat[,1],cex=1.35) abline(h=quantile(dat[,2],c(0.25,0.75)),col="red",lty=2) dev.off() dat[,4]=dat[,4]*100 ##dat=dat[-4,] dat=dat[order(-dat[,4]),] bitmap("kobe2.png",res=600,width=5,height=5) plot(dat[,4],type="n",xlab="rank",ylab="Career TS%",cex.lab=1.15) text(1:nrow(dat),dat[,4],dat[,1],cex=1.15) abline(h=quantile(dat[,4],c(0.25,0.75)),col="red",lty=2) dev.off() dat=read.table("http://rafalab.jhsph.edu/simplystats/nba.txt",header=FALSE) pos=as.character(dat[,6]);pos[pos%in%c("PF","SF")]<-"F";pos[pos%in%c("SG","PG")]<-"G";pos=factor(pos,levels=c("G","F","C")) dat[,4]=dat[,4]*100 bitmap("kobe3.png",res=600,width=7,height=5) mypar() N=47 plot(dat[1:N,5],dat[1:N,4], type="n",ylab="Career TS%",xlab="Career PPG",cex.lab=1) text(dat[1:N,5],dat[1:N,4],dat[1:N,1],cex=1,col=as.numeric(pos)) abline(lm(dat[,4]~dat[,5],subset=1:N),lty=2) legend("topright","superstar",cex=1.5,bty="n") legend("bottomright","ballhog",cex=1.5,bty="n") dev.off() bitmap("kobe4.png",res=600,width=7,height=5) mypar() N=47 plot(dat[,5],dat[,4],ylab="Career TS%",xlab="Career PPG",cex.lab=1,type="n") points(dat[1:N,5],dat[1:N,4],cex=1,pch=21,bg=as.numeric(pos)[1:N]) Names=gsub("Prime","",dat[-(1:N),1]) abline(lm(dat[,4]~dat[,5],subset=1:N),lty=2) text(dat[-(1:N),5],dat[-(1:N),4],Names,cex=1,col=as.numeric(pos)[-(1:N)]) legend("topright","superstar",cex=1.5,bty="n") legend("bottomright","ballhog",cex=1.5,bty="n") abline(lm(dat[,4]~dat[,5],subset=1:N),lty=2,col="red") dev.off() bitmap("melo.png",res=600,width=7,height=5) mypar() N=47 cexs=rep(0.75,N) cexs[dat[,1]=="Melo"]<- 1.4 cols=as.numeric(pos) cols[dat[,1]=="Melo"]<-"red" plot(dat[1:N,5],dat[1:N,4], type="n",ylab="Career TS%",xlab="Career PPG",cex.lab=1) text(dat[1:N,5],dat[1:N,4],dat[1:N,1],cex=cexs,col=cols) abline(lm(dat[,4]~dat[,5],subset=1:N),lty=2) legend("topright","superstar",cex=1.5,bty="n") legend("bottomright","ballhog",cex=1.5,bty="n") dev.off() ###if you want to make a boxplot instead ##bitmap("kobe.png",res=600) ##boxplot(dat[,2],ylab="Field goal % for 11 superstars") ##arrows(0.9,dat[9,2],0.98,dat[9,2]) ##text(0.85,dat[9,2],"Kobe") ##dev.off()