How to run pie chart for each categorical variable in a dataset?
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
Hello, What is a dataset? In R there are lots of types, including 'data.frame' and 'list'. And R's type 'factor' corresponds to categorical variables. You must be more specific, show us an example dataset using dput(). dput( head(x, 30) ) # paste the output of this in a post Hope this helps, Rui Barradas Em 02-10-2012 05:50, Leung Chen escreveu:> How to run pie chart for each categorical variable in a dataset? > > ______________________________________________ > R-help at 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.