Friday, March 03, 2006

st: graph twoway bar horizontal vs. graph hbar

Hi Statalisters,

I use Stata 9.1 for Windows XP. I am trying to draw what is supposed to be a simple bar graph. I experimented with and compared the "graph twoway bar, horizontal" and "graph hbar" commands. Please find below sample data and commands for illustration. First I tried the "graph twoway bar, horizontal" command. The resultant graph (GRAPH_01) was very close to what I wanted except that there was a small gap between the y axis and the location where bars began. Then I tried the "graph hbar" command. The resultant graph (GRAPH_02) took care of what I found lacking in GRAPH_01 but it displayed the labels of categories which I wanted to be invisible (that is, I wanted to create a gap between hospital categories); those categories are 3, 6, & 9 on the y axis.

Does anyone know: 1) How to eliminate a gap(space) between the y axis and the location where bars begin in GRAPH_01, using the "graph twoway bar, horizontal" command? 2) How to make the labels 3, 6, & 9 on the y axis (the categories intended to be invisible for an aesthetic reason) disappear, using the "graph hbar" command?

*The sample data and commands begin here ============================;

clear;

set obs 11;

gen TYPE_YEAR=.; replace TYPE_YEAR=1 in 1; replace TYPE_YEAR=2 in 2; replace TYPE_YEAR=3 in 3; replace TYPE_YEAR=4 in 4; replace TYPE_YEAR=5 in 5; replace TYPE_YEAR=6 in 6; replace TYPE_YEAR=7 in 7; replace TYPE_YEAR=8 in 8; replace TYPE_YEAR=9 in 9; replace TYPE_YEAR=10 in 10; replace TYPE_YEAR=11 in 11;

lab define TYPE_YEAR 1 "General, 1900" 2 "General, 1930" 4 "Mental, 1900" 5 "Mental, 1930" 7 "TB, 1900" 8 "TB, 1930" 10 "OS, 1900" 11 "OS, 1930"; lab val TYPE_YEAR TYPE_YEAR;

gen AVE_NUM_BED=.; replace AVE_NUM_BED=82 if TYPE_YEAR==1; replace AVE_NUM_BED=81 if TYPE_YEAR==2; replace AVE_NUM_BED=508 if TYPE_YEAR==4; replace AVE_NUM_BED=780 if TYPE_YEAR==5; replace AVE_NUM_BED=103 if TYPE_YEAR==7; replace AVE_NUM_BED=130 if TYPE_YEAR==8; replace AVE_NUM_BED=68 if TYPE_YEAR==10; replace AVE_NUM_BED=60 if TYPE_YEAR==11;

graph twoway (bar AVE_NUM_BED TYPE_YEAR, horizontal barwidth(.8) fcolor(gs0) lstyle(solid) lw(thin)),

title("Average Number of Beds", size(medsmall) margin(medsmall))

ytitle("") xtitle("")

ylabel(1 2 4 5 7 8 10 11, labsize(vsmall) valuelabel angle(horizontal) nogrid notick) xlabel(0 50 100 (100) 800, labsize(vsmall) grid gmax gmin)

xline(50 100, lw(vthin))

saving(GRAPH_01, replace);

graph hbar (asis) AVE_NUM_BED if TYPE_YEAR!=., over(TYPE_YEAR, label(labsize(vsmall)) gap(50))

bar(1, fcolor(gs0) lstyle(solid) lw(thin))

title("Average Number of Beds", size(medsmall) margin(medsmall))

ylabel(0 50 100 (100) 800, labsize(vsmall) grid gmax gmin) ytitle("") yline(50 100, lw(vthin))

saving(GRAPH_02, replace);

*The same data and commands end here ==============================;

Thank you in advance. ---Hiroshi

--------------------------------- Hiroshi Maeda University of Illinois at Chicago

* * 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/


Tag:


Links to this post:

Create a Link



<< Home

This page is powered by Blogger. Isn't yours?