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

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to