args <- commandArgs(trailingOnly=TRUE); d<-args[1]
a<-read.csv(file.path(d,'weekly-scores-ranks.csv'),stringsAsFactors=FALSE)
z<-read.csv(file.path(d,'weekly-changes.csv'),stringsAsFactors=FALSE)
g<-read.csv(file.path(d,'exploratory-neighbor-groups.csv'),stringsAsFactors=FALSE)
navy<-'#153B50';teal<-'#007F83';muted<-'#536574';grid<-'#DFE6E9';cols<-c('#007F83','#C35B30','#6250A1','#2878B5','#9B6A17','#A73869')
base<-function(){par(family='sans',col=navy,col.axis=muted,col.lab=navy,fg=navy,bty='n',las=1,cex=0.95,oma=c(3.4,2,3,1))}
finish<-function(title,note){mtext(title,side=3,outer=TRUE,line=1,cex=1.35,font=2,col=navy);mtext('Exploratory research | 2025 retrospective v0.57 reconstruction | October 29, 2026',side=1,outer=TRUE,line=.3,cex=.8,col=muted);for(q in seq_along(strwrap(note,width=145)))mtext(strwrap(note,width=145)[q],side=1,outer=TRUE,line=1.2+(q-1)*.8,cex=.75,col=muted)}
render<-function(name,fun){for(ext in c('png')){if(ext=='png')png(file.path(d,paste0(name,'.png')),width=1800,height=1100,res=150,type='quartz') else svg(file.path(d,paste0(name,'.svg')),width=12,height=1100/150);base();fun();dev.off()}}
render('01-score-spacing',function(){v<-subset(a,checkpoint==6 & rank<=30);layout(matrix(1:2,1,2),widths=c(2.3,1.4));par(mar=c(4,9.7,2,1));plot(v$index,v$rank,xlim=c(min(v$index)-2,101),ylim=c(30.6,.4),yaxt='n',xlab='Reconstructed NRR Index (0–100)',ylab='',pch=19,col=teal,cex=.8);axis(2,at=v$rank,labels=paste0(v$rank,'. ',v$team),cex.axis=.68);abline(h=v$rank,col=grid,lwd=.5);points(v$index,v$rank,pch=19,col=teal,cex=.8);text(v$index+.5,v$rank,sprintf('%.2f',v$index),pos=4,cex=.62,col=navy);title('Selection checkpoint: December 7, 2025',cex.main=.95);par(mar=c(4,1,2,2));plot(v$gapToNext,v$rank,xlim=c(0,max(v$gapToNext)*1.35),ylim=c(30.6,.4),yaxt='n',xlab='Index gap to the next ranked team',ylab='',type='n');abline(h=v$rank,col=grid,lwd=.5);segments(0,v$rank,v$gapToNext,v$rank,col=teal,lwd=3);text(v$gapToNext,v$rank,sprintf(' %.3f',v$gapToNext),pos=4,cex=.65);title('A rank step is not a fixed score gap',cex.main=.95);finish('Nearby ranks can hide very different score gaps','Gaps are arithmetic differences, not uncertainty intervals or proof that teams belong in separate groups.')})
render('02-weekly-ranks-and-scores',function(){teams<-c('Notre Dame','Alabama','Oklahoma','Utah','Oregon','Clemson');v<-subset(a,team %in% teams);layout(matrix(1:2,1,2));dates<-as.Date(sort(unique(v$date)));labs<-format(dates,'%b %d');par(mar=c(6,4,2,1));plot(1,type='n',xlim=c(1,6),ylim=c(max(v$rank)+3,1),xaxt='n',yaxt='n',xlab='',ylab='NRR rank (selected range)');axis(2,at=unique(c(1,pretty(range(v$rank)))));axis(1,at=1:6,labels=labs,las=2,cex.axis=.8);abline(h=pretty(range(v$rank)),col=grid);for(j in seq_along(teams)){t<-subset(v,team==teams[j]);lines(t$checkpoint,t$rank,col=cols[j],lwd=2,type='b',pch=j,cex=.65)};title('Rank: who is above or below whom?',cex.main=.95);par(mar=c(6,4,2,1));plot(1,type='n',xlim=c(1,6),ylim=c(0,100),xaxt='n',xlab='',ylab='Reconstructed NRR Index');axis(1,at=1:6,labels=labs,las=2,cex.axis=.8);abline(h=seq(0,100,20),col=grid);for(j in seq_along(teams)){t<-subset(v,team==teams[j]);lines(t$checkpoint,t$index,col=cols[j],lwd=2,type='b',pch=j,cex=.65)};title('Score: how much does the index change?',cex.main=.95);legend('bottomleft',legend=teams,col=cols,lty=1,pch=1:6,cex=.69,bty='n',ncol=2);finish('Rank movement and score movement answer different questions','Six illustrative teams; six late-season checkpoints. These are later-method restatements, not contemporaneous rankings.')})
render('03-weekly-change-diagnostic',function(){par(mar=c(4.6,5,2,2));plot(z$indexChange,z$rankImprovement,pch=16,col=adjustcolor(teal,alpha.f=.25),cex=.8,xlab='Change in reconstructed NRR Index',ylab='Rank improvement (old rank minus new rank)');abline(h=0,v=0,col=muted,lty=2);title(sprintf('%d matched team-week changes across all 136 teams',nrow(z)),cex.main=1);legend('topleft',legend=c('Each dot = one team between adjacent checkpoints','Positive y = rank improves; negative y = rank worsens'),bty='n',cex=.85);finish('A score change does not map to one fixed rank change','Descriptive diagnostic only. Repeated teams are dependent; no fitted trend, significance or changepoint claim.')})
render('04-exploratory-group-sensitivity',function(){thresholds<-sort(unique(g$threshold));par(mar=c(5,8,2,2));v<-subset(g,rank<=30);plot(1,type='n',xlim=c(min(v$index)-2,101),ylim=c(.5,4.5),yaxt='n',xlab='Reconstructed NRR Index: Selection checkpoint, top 30 displayed',ylab='');axis(2,at=1:4,labels=paste0('Neighbor gap ≤ ',thresholds),cex.axis=.8);for(i in seq_along(thresholds)){all<-subset(g,threshold==thresholds[i]);t<-subset(all,rank<=30);for(k in unique(t$group)){s<-subset(t,group==k);cc<-cols[(k-1)%%length(cols)+1];segments(min(s$index),i,max(s$index),i,col=cc,lwd=5);points(s$index,rep(i,nrow(s)),pch=21,bg='white',col=cc,cex=.9)};text(min(v$index)-1.2,i+.28,paste0(max(all$group),' groups in full 136-team field'),pos=4,cex=.72,col=muted)};finish('Exploratory score groups change when the rule changes','Arbitrary gap thresholds, not validated clusters. Single-link chaining can join wide ranges; colors repeat and do not track groups across rows.')})
