R-Making Piechart By Groups
id sample(%)
R1 45
R2 25
R3 77
R4 0
R5 100
:
:
R10000 58
I want to create a pie chart in R by grouping on percentage with labels as shown in figure 0-20% 20-40% 40-60% 60-80% 80-100%

• 8,777 views
•
link
1 answer
Did you tried to look up some manual/tutorial how to do it.
Anyways,
# make data frame
df=data.frame(id=paste('R',seq(1,5),sep=''),value=as.numeric(c('45','25','77','0','100')))
# making groups
grp1=subset(df,value<26)
grp2=subset(subset(df,value>26),value<=46)
grp3=subset(subset(df,value>26),value<=80)
grp4=subset(subset(df,value>80),value<=100)
# calculating %ages for slice
slice<-c(length(grp1[,1])/length(df[,1]),length(grp2[,1])/length(df[,1]),length(grp3[,1])/length(df[,1]),length(grp4[,1])/length(df[,1]))*100
# make pie
pie(slice,labels=paste(slice,'%',sep=''),main="My pie chart")
Cheers
P.S. Try asking at stack overflow for computing related questions.
• 1 views
•
link
Log in to answer this question.
As it stands this is an R-programming related question, better suited to stackoverflow.com, not a bioinformatics question. Closing it on that basis. Also, most data visualization experts recommend you not use pie charts in most cases (basically, because human eyes are rubbish at comparing relative areas).
In the words of John McEnroe, "You can not be serious!" While I agree with your assessment that pie charts suck at conveying information for the reasons you mentioned, forbidding their discussion is a bit macabre. Biologists use them constantly in publications and presentations to display biological information. People discuss how to do x in their language of choice here every day. I submit that pie charts, and how to draw them in R is related to bioinformatics. It's hard for me to imagine why this question was closed.
Closed because, as I said, the question as written is a pure R programming question as opposed to a bioinformatics research question. Nothing to do with banning discussion. If the questioner wants to make their question more relevant to this forum, happy to reopen.
Well then if discussion is still open, then I'll just add that I found the "grouping data" aspect of the question the most interesting. The idea that methods of grouping data and displaying the results is not relevant to bioinformatics research, something I do every day in my bioinformatics research, is still beyond my comprehension. Good thing realities are negotiated rather than dictated. I was also prompted to think of times when a pie chart is preferable over other methods. A recent lab meeting I attended where people spent way too much time haggling over small differences in area of a bar chart was a complete waste of time (the differences weren't meaningful). On a pie chart the subtle differences would have been obscured, thus I think pie charts can be good for making a point comparing really small slices to really big slices (i.e. good for very different areas, but not for similar areas).
The question may well have relevance to bioinformatics but as written, it is not clear what that relevance is - it is a pure R programming question. We have always either redirected such questions to a programming forum, usually stackoverflow and/or asked the questioner to restate the question in terms of a bioinformatics problem.