Statalist


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

Re: st: labels on bar graphs


From   Richard Goldstein <[email protected]>
To   [email protected]
Subject   Re: st: labels on bar graphs
Date   Mon, 30 Jun 2008 16:27:54 -0400

Thanks to all who replied -- none of the responses were perfect ;-)

Svend's comes closest; however, the idea of using -contract- and then reloading the data prior to dozens of graphs is not very appealing.

Thanks again,

Rich

Svend Juul wrote:

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: [email protected]
__________________________________________
*
*   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/



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