分割表を図示

TablePlot(N=100,M=100,r=0.7)
TablePlot<-function(N=2,M=2,Ns=1000,r=0.5,k1=10,k2=10){
 first<-sample(1:N,Ns,prob=rep(k1,N),replace=TRUE)
 second<-sample(1:M,Ns,prob=rep(k2,M),replace=TRUE)
 Nr<-Ns*r
 first[1:Nr]<-sort(first[1:Nr])
 second[1:Nr]<-sort(second[1:Nr])

 t<-table(first,second)
 
 plot(t)
 t
}

TableImage<-function(N=2,M=2,Ns=1000,r=0.5,k1=10,k2=10){
 first<-sample(1:N,Ns,prob=rep(k1,N),replace=TRUE)
 second<-sample(1:M,Ns,prob=rep(k2,M),replace=TRUE)
 Nr<-Ns*r
 first[1:Nr]<-sort(first[1:Nr])
 second[1:Nr]<-sort(second[1:Nr])
 t<-table(first,second)
 
 image(t)
}

TableFilledContour<-function(N=2,M=2,Ns=1000,r=0.5,k1=10,k2=10){
 library(gregmisc)
 first<-sample(1:N,Ns,prob=rep(k1,N),replace=TRUE)
 second<-sample(1:M,Ns,prob=rep(k2,M),replace=TRUE)
 Nr<-Ns*r
 first[1:Nr]<-sort(first[1:Nr])
 second[1:Nr]<-sort(second[1:Nr])
 h2d <- hist2d(first, second, show = FALSE, same.scale = TRUE, nbins = c(10,10))
 filled.contour(h2d$x, h2d$y, h2d$counts, nlevels = 10, col = gray((10:0)/10))

}

TablePersp<-function(N=2,M=2,Ns=1000,r=0.5,k1=10,k2=10){
 library(gregmisc)
 first<-sample(1:N,Ns,prob=rep(k1,N),replace=TRUE)
 second<-sample(1:M,Ns,prob=rep(k2,M),replace=TRUE)
 Nr<-Ns*r
 first[1:Nr]<-sort(first[1:Nr])
 second[1:Nr]<-sort(second[1:Nr])
 h2d <- hist2d(first, second, show = FALSE, same.scale = TRUE, nbins = c(10,10))
 persp(h2d$x, h2d$y, h2d$counts, ticktype = "detailed", theta = 60,phi = 30, shade = 0.5, col = "cyan")
}