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 <[email protected]>
To   [email protected]
Subject   Re: st: RE: RE: Graph bar with label wtih % symbol at the top of each bar
Date   Fri, 11 May 2012 09:48:35 +1000

Just a note of caution - the bars are numbered from 1 to n, left to right. In my example below those numbers corresponded exactly with the levels of rep78, but that often won't be the case. So you need to be careful that you label the correct bars.

Phil

On 11/05/2012, at 9:39 AM, Phil Clayton wrote:

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


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