Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: RE: Graph bar with label wtih % symbol at the top of each bar


From   Phil Clayton <philclayton@internode.on.net>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: RE: Graph bar with label wtih % symbol at the top of each bar
Date   Fri, 11 May 2012 09:39:46 +1000

On 11/05/2012, at 8:21 AM, David Radwin wrote:
> ... I don't think you can get percentage symbols to show as bar labels without the graph editor

You can, however, invoke the graph editor from within your do-file to automate the process of changing the bar labels to percentages. Here's a simple example:

------- begin example -------
sysuse auto, clear
graph bar (mean) foreign, over(rep78) blabel(bar) ///
	ytitle(% foreign) ylab(0 .2 "20" .4 "40" .6 "60" .8 "80" 1 "100")

* for each level of rep78, replace the proportion in the bar label with a %
foreach rep of numlist 1/5 {
	sum foreign if rep78==`rep', meanonly
	local lab: di %1.0f 100*r(mean)
	_gm_edit .Graph.plotregion1.barlabels[`rep'].text = {}
	_gm_edit .Graph.plotregion1.barlabels[`rep'].text.Arrpush `lab'%
}

* now re-draw the graph with the new labels
graph display Graph
-------end example -------

Of course, if you gave your graph a name then you should use that name rather than Graph in the _gm_edit and -graph display- commands.

How to determine the commands to use? If you record your edits using the GUI graph editor, you can open the recording file (which is just a text file) and see what's been recorded.

Phil



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index