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: graph hbar, over, and bar coloring


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: graph hbar, over, and bar coloring
Date   Wed, 2 Mar 2011 12:16:13 +0000

Stephen's problem as I understand it can be simulated like this:

clear
set obs 30
egen cat1 = seq(), to(5)
egen cat2 = seq(), block(5)
gen percent = 80 * runiform()
gr hbar percent , ///
       over(cat1) over(cat2) scale(.75)            ///
       ytitle("Percentage") ylabel(0(10)80) ytick(0(5)80)      ///
       scheme(s2mono) graphregion(color(white) )

I suggest using -separate- first. The corresponding values are then
disjoint, and the bars can be further tuned using -bar(1, ...)- and
-bar(2, ...)-.

separate percent, by(cat1 > 3)

gr hbar percent0 percent1 , ///
       over(cat1) over(cat2) scale(.75)            ///
       ytitle("Percentage") ylabel(0(10)80) ytick(0(5)80)      ///
       scheme(s2mono) graphregion(color(white) )

Nick

On Wed, Mar 2, 2011 at 11:49 AM,  <[email protected]> wrote:
> I have -graph hbar- commands that look like
>
>
> gr hbar percent ,
> ///
>        over(period) over(agegp3) missing scale(.75)            ///
>        ytitle("Percentage") ylabel(0(10)80) ytick(0(5)80)      ///
>        scheme(s2mono) graphregion(color(white) )
>
> where period takes on 5 values, and agegp3 takes on 6 values. Nicely
> plotted are the bars for each period within each age group. Ideally,
> however, I would like to plot the first 3 bars corresponding to the
> first 3 values of period to be shown in black, and the last 2 bars
> corresponding to the last 2 values of period to be shown in grey.
>
> Simply adding a -bar(#, color(..))- option to the command does not
> produce what I want. Suggestions please.  Or is it not possible to
> combine barcolor options as I wish when -over()- options are also used?
>
> I've looked in Michael Mitchell's book, 2/e, section 5.8. on changing
> the look of bars, and this suggests to me that I need to define
> "percent" separately for different values of period (say percent1 and
> percent2). E.g.
> gen percent1 = percent if inlist(period, 1, 2, 3)
> gen percent2 = percent if inlist(period, 4, 5)
> However when I did this (-gr hbar percent1 percent2, ... etc....) there
> was no colour change as I'd hoped, and the bars were thinner.
>
> For similar issues, cf.
>
> . sysuse auto, clear
> (1978 Automobile Data)
>
> . gr hbar weight, over(foreign)
>
> . gr hbar weight, over(foreign) bar(1, color(black)) bar(2, color(gs8))
>
> I would have hoped that the bar coloring would cycle within the over
> group, but it doesn't.

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