[FORGED] turning the output of cut into a waffle plot
Hi Rolf, About the only reason I would hesitate is package bloat. There are now 167 functions listed in the package. I posted the cut2matrix function for the benefit of those who had been following the thread, but it seems like a very peculiar way of displaying data. While I encourage trying things out, as there is a lot left to discover, I would like to be sure that more than one person sees a use for it. Jim
On Wed, Jan 18, 2017 at 5:37 PM, Rolf Turner <r.turner at auckland.ac.nz> wrote:
On 18/01/17 12:21, Jim Lemon wrote:
Hi all,
A few days ago I offered a suggestion on how to display the initial
values that were cut into a factor as a waffle plot. As Rolf Turner
noted, a major problem for users would be constructing the matrix that
was fed to the color2D.matplot function. Here is a fairly general
purpose function for that with an example from the initial post.
egdat <- c(137,135,144,149,150,152,159,157,154,163,164,164,
161,162,165,164,179,173,173,182,180,185,180,197,190)
cut2matrix<-function(x,breaks,ncol,nrow,right=TRUE) {
xcut<-as.numeric(cut(x,breaks=breaks,right=right))
if(missing(ncol)) ncol<-length(breaks)-1
if(missing(nrow)) nrow<-max(table(xcut))
xlist<-vector("list",ncol)
for(xind in 1:ncol) xlist[[xind]]<-rev(x[xcut==xind])
xdf<-as.data.frame(lapply(xlist,function(x) x[1:nrow]))
names(xdf)<-paste("V",1:ncol,sep="")
return(as.matrix(sapply(xdf,rev)))
}
egmat<-cut2matrix(egdat,seq(120,210,by=10),9,8,FALSE)
library(plotrix)
color2D.matplot(egmat,show.values=TRUE)
Nice work Jim. Will the cut2matrix() function now be added to the plotrix package? cheers, Rolf -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276