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: graph hbar - different colors for different groups defined by an external variables


From   Joe Canner <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: RE: graph hbar - different colors for different groups defined by an external variables
Date   Fri, 20 Sep 2013 18:35:53 +0000

Alice,

I think I finally found something that might work (albeit not very elegantly).  I got something similar to this to work with the auto data; some tweaking might be required to get it to work for your situation:

collapse (mean) g0, by(regione geo)
gsort -g0
gen g0sort=_n
separate g0, by(g0sort)
gen color="white" if geo=="Central"
replace color="gray" if geo=="South"
replace color="black" if geo="North"
forval j = 1/20 {         // Or however many regions there are
   local thislab=regione[`j']
   local lab `lab' `j' "`thislab'"
   local col=color[`j']
   local call `call' || bar g0`j' g0sort, horiz bcolor(`col') legend(off) ylabel(1(1)20, valuelabel angle(0))     // make 20=your number of regions
}

label define g0label `lab'
label value g0sort g0label

twoway `call'

Good luck!

Joe


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Alice Guerra
Sent: Friday, September 20, 2013 11:17 AM
To: [email protected]
Subject: Re: st: RE: graph hbar - different colors for different groups defined by an external variables

Thank you Joe,

my command is

graph hbar (mean) g0, over(regione, sort(g0) descending label(labsize(vsmall)))

The graph that I would like to obtain have on the yaxis the name of the Italian regions, and the color of their bars should reflect their geographical position. For example, if the first region at the top of the y-axis  is Lombardy, and Sicily is the second one, I would like to color the first bar in black (color that corresponds to the North), and the second in gray (color of the South).

Thank you for your help

Alice

On 20 September 2013 17:07, Joe Canner <[email protected]> wrote:
> Alice,
>
> Try:
>
> . graph hbar yvar, over(geo) asyvars bar(1, color(black)) 
> bar(2,color(gray)) bar(3,color(white))
>
> Or were you hoping to have something more general that doesn't depend on knowing the ordering of the -geo-?
>
> Regards,
> Joe Canner
> Johns Hopkins University School of Medicine
>
> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of Alice 
> Guerra
> Sent: Friday, September 20, 2013 10:53 AM
> To: [email protected]
> Subject: st: graph hbar - different colors for different groups 
> defined by an external variables
>
> Dear Statalists,
>
> I was wondering if it would be possible to have different colors in a graph hbar for different groups. The groups are defined by an external variable.
>
> In my dataset, I have the Italian regions. I want to plot them in a graph hbar, and I want to color the bars of the Northern regions in black, the bars of the Southern regions in gray, and the central regions in white. the external variable for the geographic ripartition of regions is called "geo".
>
> Thank you for your time and help.
>
> Best regards
>
> Alice
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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