Hi Maybe factor strikes again.
r-help-boun...@r-project.org napsal dne 24.02.2010 15:21:50: > Hi, > > I want to draw a pie chart of level (variable) for each ID (variable). I have > a big dataset, here I attach part of it. > > > ID level > 1 G1 > 1 A1 > 1 A1 > 1 G1 > 1 G1 > 1 G1 > 1 A1 > 1 A1 > 1 G1 > 1 G1 > 1 G3 > 1 A1 > 1 G1 > 1 A1 > 1 A1 > 1 A2 > 1 A2 > 1 M > 1 A1 > 1 G1 > 1 A1 > 1 > > 1 > > 1 A2 > 1 G3 > 1 A1 > 1 A1 > 1 A1 > Below is my r code: > level <- na.exclude(level) Did you attach your dataset before? If not from where you have got your "level" variable. > level.table <- table(level) > level.sum <- sum(level.table ) > lbls <- round(level.table /level.sum*100,1) prop.table(table(level))*100 seems to be better choice > lbls <- paste(lbls,"%",sep="") > pie(level.table,labels=lbls,col=rainbow(length(level.table)),radius=0.5,cex=0.9) > > The problem is the na.exclude function does not work here. Is it the reason > that my missing values are not 'NA's but blank? How can I get the pie chart Probably yes. If level is a factor you could check by levels(level) If there is "" level you can change it to NA level[level==""] <- NA or maybe to set NA values during reading your data see ?read.table Than na.* functions shall work as expected. Regards Petr BTW, piechart is not encouraged by many people here. You probably can have better options with R how to compare data. > without those missing values? > > Thank you, > Lu > > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. ______________________________________________ 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.