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: Fwd: graph/histogram: Can I change the color for each histogram bar/bin separately?


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Fwd: graph/histogram: Can I change the color for each histogram bar/bin separately?
Date   Tue, 24 Sep 2013 17:49:01 +0100

Some technique:

sysuse auto

twoway histogram foreign if foreign, bcolor(red) discrete barw(0.8) freq  ///
|| histogram foreign if !foreign, bcolor(blue) barw(0.8)  discrete
         ///
by(rep78,  legend(off) note("")) freq xla(0 1, valuelabel tlength(0))

The main idea is that different bar colours mean different histograms,
which must be superimposed. The easy way to do that is with
frequencies. Doing that with -histogram- is not out of the question,
but ungainly compared with repeated calls to -twoway histogram-.

I dislike ticks when categories are qualitative, as ticks to me imply
position on a numeric scale. The -noticks- suboption seems
recalcitrant, but -tlength(0)- works. I suppose that means there are
ticks, but it's just difficult to see them if they are of zero length.
Nick
[email protected]


On 24 September 2013 17:18, Victor Ciofoaia <[email protected]> wrote:
> Hello everybody!
>
> I will skip the first thing I desperately burn to say "this is my
> first email to statalist, stata is great! " :)
>
> I need to do a graph and I managed to make it look nicely as I wanted
> with the by option, getting a 12 years trend:
>
> .histogram surgery_type, discrete by(year, total col(12))
>
> The histogram is actually done for just 4 values(1-4), but I would
> like to emphasize how the frequencies changed - a trend in the
> histogram and I could not figure out how to change the color bars in
> histogram. I can change the color for all the bars, but not for the
> 1st bin (ed reg), 2nd bin ( eg blue) etc... Is there a way to do this
> for a histogram?
>
> I assume I could somehow build a histogram from scratch, but that
> would be too complicated for me at my training point. BTW, is there an
> easy way to make your own histogram from scratch if changing color
> bars does not work?
>
> Thank you very much for any advice on where to go from here.
>
> Victor
> *
> *   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