[R] Add percentage to pie (was "(no subject)")

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Mon Sep 18 17:15:18 CEST 2006

ERICK YEGON said the following on 9/18/2006 8:22 AM:
> Hi Gurus, i have a small problem with working with graphs on R.
> Say i have  data say bull-c(34,23,7,4) and i assign names to the elements in 
> the brackets
> if i do
> Pie(bull) i get a pie chart of bull  togtjer with the names.
> Question. How can i add values (percentages) in the graph
> Thanks
> ______________________________________________
> R-help at stat.math.ethz.ch 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.

(Please use a sensible subject line!)

Where do you want to add percentages? If next to the labels, then just use:

bull <- c(34, 23, 7, 4)
names(bull) <- LETTERS[seq(along = bull)]
lbl <- sprintf("%s = %3.1f%s", names(bull), bull/sum(bull)*100, "%")
pie(bull, lbl)


More information about the R-help mailing list