# # book_ch_2_fig_11.r -- Does Two-Dim Plot of Artificial Voting Data # # Figure 2.11 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 # # 88 409 74822 74 27 101 6 6 1 -0.341 -0.801 -0.599 # ws <- 0.375 N1 <- 0.600 N2 <- 0.800 # plot(T[,5],T[,6],type="n",asp=1, main="Figure 2.11: Twelve Legislator Example\nNormal Vector and Normal Vector Line", 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 and its Reflection # arrows(0.0,0.0,N1,N2,length=0.1,lwd=2,col="black") arrows(0.0,0.0,-N1,-N2,length=0.1,lty=2,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="red4",adj=0,cex=1.2) text(xws-xktp*N2-xktp2*N1,yws+xktp*N1-xktp2*N2,expression(O[n]),col="blue4",adj=1,cex=1.2) # text( 1.0,-.45,"Cutting\nLine",col="black",cex=1.2) text( 0.7, .85,expression(N[j] == group("(",list(.8, .6),")")),col="black",cex=1.2) text(-0.7,-.8,expression(-N[j]),col="black",cex=1.2) text( 0.05, .55,expression(Z[j]),col="black",cex=1.2) # # Put Black Dot at Zj # points(xws-xktp*N2,yws+xktp*N1,pch=16,col="black") # # # Put Black Dot at Mj # points(xws,yws,pch=16,col="black") # text( xws, yws,expression(M[j]),col="black",pos=4,cex=1.2) text( 0.0, -.85,"Cutting Line = .6X1 + .8X2 = .37",col="black",cex=1.2)