Tammy Ma
2013-Mar-15 13:58 UTC
[R] How to make the labels of pie chart are not overlapping?
I have the following dataframe: Product predicted_MarketShare Predicted_MS_Percentage A 2.827450e-02 2.8 B 4.716403e-06 0.0 C 1.741686e-01 17.4 D 1.716303e-04 0.0 ....... Because there are so many products, and most of predicted Market share is around 0%. When I make pie chart, the labels of those product with 0% market share are overlapping. How do I make the labels are not overlapping? Kind regards. Tammy [[alternative HTML version deleted]]
Bert Gunter
2013-Mar-15 16:30 UTC
[R] How to make the labels of pie chart are not overlapping?
Simple -- don't make a pie chart. -- Bert (Seriously -- this is an awful display. Consider, instead, a bar plot plotting cumulative sums of percentages with products/bars ordered from largest percentage to smallest; or plotting just the percentages in that order, depending on which is more informative.) On Fri, Mar 15, 2013 at 6:58 AM, Tammy Ma <metal_licaling@live.com> wrote:> I have the following dataframe: > > Product predicted_MarketShare Predicted_MS_Percentage > A 2.827450e-02 2.8 > B 4.716403e-06 0.0 > C 1.741686e-01 17.4 > D 1.716303e-04 0.0 > ....... > > Because there are so many products, and most of predicted Market share is > around 0%. > When I make pie chart, the labels of those product with 0% market share > are overlapping. > How do I make the labels are not overlapping? > > Kind regards. > Tammy > > [[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. >-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[alternative HTML version deleted]]
Jim Lemon
2013-Mar-15 22:01 UTC
[R] How to make the labels of pie chart are not overlapping?
On 03/16/2013 12:58 AM, Tammy Ma wrote:> I have the following dataframe: > > Product predicted_MarketShare Predicted_MS_Percentage > A 2.827450e-02 2.8 > B 4.716403e-06 0.0 > C 1.741686e-01 17.4 > D 1.716303e-04 0.0 > ....... > > Because there are so many products, and most of predicted Market share is around 0%. > When I make pie chart, the labels of those product with 0% market share are overlapping. > How do I make the labels are not overlapping? >Hi Tammy, Obviously you have many more products than are shown above. Let us assume that their market share is distributed approximately as negative binomial and your "C" value is the maximum. You might have twenty products with market shares around: market_share<-c(0,0,0,0,1,1,1,1,2,2,3,3,4,5,5,6,10,11,15,17) names(market_share)<-LETTERS[1:20] If you try to plot this as a pie chart: pie(market_share) you do get a bunch of overprinted labels for the four zero values. Pie charts with more than four or five sectors are usually not the best way to display the distribution of your values, but if you must: par(mar=c(5,4,4,4)) pie(market_share,labels=c(rep("",4),names(market_share)[5:20])) par(xpd=TRUE) text(1.1,0,"A,B,C,D=0") par(xpd=FALSE) Good luck with it. Jim