On 10/02/2012 02:50 PM, Leung Chen wrote:
How to run pie chart for each categorical variable in a dataset?

Hi Leung,
I depends upon your definition of "categorical". If a character variable has 100 possible values, you won't get a very informative pie chart out of it. Therefore I suggest the following function as a start:

pie_shopping<-function(x,maxval=5) {
 xname<-deparse(substitute(x))
 for(var in 1:length(x)) {
  if(length(unique(x[,var])) <= maxval) {
   png(paste(xname,var,".png",sep=""))
    pie(table(x[,var]))
   dev.off()
  }
 }
}

Jim

______________________________________________
R-help@r-project.org mailing list
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