[R] (no subject)

Greg Snow Greg.Snow at intermountainmail.org
Mon Sep 18 18:55:36 CEST 2006


You may want to rethink your whole approach here:

1. Pie charts are usually a poor choice of graph, there are better
choices.
2. Adding percentages to a pie chart is a way of admitting that the pie
chart is not doing the job.
3. If you want people to compare percentages, then a table is what is
needed.
4. A pie chart with percentages added is essentially a colorful but
poorly layed out table.

Consider using a dotplot instead of a pie chart, it changes the job of
the viewer from comparing areas/angles (done poorly by humans) to
comparing positions along a common scale (done well by humans).

If you still feel the need to combine the table and graphic into 1
(usually they serve different purposes and are best kept separate) then
you can do something like this (at least the percentages are all aligned
now for easy comparison):

> library(lattice)
> bull<-c(34,23,7,4)
>
> bull.df <- data.frame(bull=bull, name=LETTERS[1:4],
pb=round(bull/sum(bull)*100,2))
> dotplot(name~pb, data=bull.df, 
+	scales=list( 
+		x=list(limits=c(0,100)),
+	),
+	panel=function(x,y,...){
+		panel.dotplot(x,y,...)
+		ltext(100,y,paste(format(x),"%",sep=''),adj=1,xpd=NA)
+	}
+ )

It would look even better if the percentages were outside the box, but I
did not have the time to figure this part out.

Hope this helps,


-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
 

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of ERICK YEGON
Sent: Monday, September 18, 2006 7:22 AM
To: r-help at stat.math.ethz.ch
Subject: [R] (no subject)

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.



More information about the R-help mailing list