[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
Svend Juul <SJ@SOCI.AU.DK> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: labels on bar graphs |

Date |
Mon, 30 Jun 2008 09:55:51 +0200 |

Rich wrote: I need to produce a sizable number of bar graphs for a client. The client wants the y-axis to be labeled as, e.g., "15%" rather than as, e.g., .15. The range of proportions for these graphs varies quite a bit (from a max of less than .05 to a max of over .2) so I don't want to force them all to be the same. After seeing a graph, it is easy enough to use the ylabel option to get what I want. Given that I am generally willing to live with Stata's automatic choice of tick marks, is there a way to automatically get labels in the form I want (e.g., "15%") rather than the way Stata wants (e.g., .15)? ====================================================================== You could -contract- the dataset, determine the maximum percent, and create a macro containing a label corresponding to that. Here is an example: ------------------------------------------------------------- sysuse auto , clear contract rep78 , percent(pct) nomiss local pmax = r(max)/r(sum) if `pmax' < .05 { local ylab `" 0 " 0% " 1 " 1% " 2 " 2% " 3 " 3% " 4 " 4% " 5 " 5% " "' } else if `pmax' < .10 { local ylab `" 0 " 0% " 2 " 2% " 4 " 4% " 6 " 6% " 8 " 8% " 10 " 10% " "' } else if `pmax' < .20 { local ylab `" 0 " 0% " 5 " 5% " 10 " 10% " 15 " 15% " 20 " 20% " "' } else { local ylab `" 0 " 0% " 10 " 10% " 20 " 20% " 30 " 30% " 40 " 40% " 50 " 50% " "' } graph bar pct , over(rep78) ylabel(`ylab') ------------------------------------------------------------- Hope this helps Svend __________________________________________ Svend Juul Institut for Folkesundhed, Afdeling for Epidemiologi (Institute of Public Health, Department of Epidemiology) Vennelyst Boulevard 6 DK-8000 Aarhus C, Denmark Phone: +45 8942 6090 Home: +45 8693 7796 Email: sj@soci.au.dk __________________________________________ * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: labels on bar graphs***From:*Richard Goldstein <richgold@ix.netcom.com>

**RE: st: labels on bar graphs***From:*"Martin Weiss" <martin.weiss@uni-tuebingen.de>

- Prev by Date:
**Re: st: RE: gllamm or else?** - Next by Date:
**RE: st: labels on bar graphs** - Previous by thread:
**Re: st: labels on bar graphs** - Next by thread:
**RE: st: labels on bar graphs** - Index(es):

© Copyright 1996–2015 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |