# # book_ch_2_fig_7.r -- Does Two-Dim Plot of Artificial Voting Data # # Figure 2.7 of the Book # library(MASS) library(pcurve) # T <- matrix(scan("C:/R_Files/book_ch_3_vote1.txt",0),ncol=7,byrow=TRUE) # # # Cutting Line # ws <- 0.375 N1 <- 0.600 N2 <- 0.800 # plot(T[,5],T[,6],type="n",asp=1,main="Figure 2.7: Twelve Legislators in\nTwo Dimensions", xlab="", ylab="", xlim=c(-1.0,1.0),ylim=c(-1.0,1.0)) # # Yea points(T[T[,7]==1,5],T[T[,7]==1,6],pch='Y',col="red") # Nay points(T[T[,7]==6,5],T[T[,7]==6,6],pch='N',col="blue") # # Plot Cutting Line # # This computes the point on the Normal Vector # Through which the Cutting Line passes # xws <- ws*N1 yws <- ws*N2 # # This computes the Cutting Line # arrows(xws,yws,xws+N2,yws-N1,length=0.0,lwd=2,col="black") arrows(xws,yws,xws-N2,yws+N1,length=0.0,lwd=2,col="black") # # This does the Normal Vector # arrows(0.0,0.0,N1,N2,length=0.1,lwd=2,col="black") # # This Does the Dotted Line Between The Two Outcome Points # xktp <- .2 xktp2 <- .3 arrows(xws-xktp*N2,yws+xktp*N1,xws-xktp*N2+xktp2*N1,yws+xktp*N1+xktp2*N2,length=0.0,lty=2,lwd=3,col="black") arrows(xws-xktp*N2,yws+xktp*N1,xws-xktp*N2-xktp2*N1,yws+xktp*N1-xktp2*N2,length=0.0,lty=2,lwd=3,col="black") # # Labels For Outcome Points # text(xws-xktp*N2+xktp2*N1,yws+xktp*N1+xktp2*N2,expression(O[y]),col="red",adj=0,cex=1.2) text(xws-xktp*N2-xktp2*N1,yws+xktp*N1-xktp2*N2,expression(O[n]),col="blue",adj=1,cex=1.2) # text( 1.0,-.45,"Cutting\nPlane") text( 0.825, .8,"Normal\nVector")