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
William Buchanan <[email protected]>
To
[email protected]
Subject
Re: st: Fwd: graph/histogram: Can I change the color for each histogram bar/bin separately?
Date
Tue, 24 Sep 2013 11:54:17 -0500
Hi Victor,
I would check out the program -catplot- written by Nick Cox. You don't necessarily need/want a histogram if there are only 4 possible values; you just want bar graphs where the height of the bars indicate the frequency of each category.
HTH,
Billy
/* Examples */
clear
set obs 12 // This will be for each year
g year=_n // Years will be from 1-12
expand 1000 // 1000 observations per year
g noise=runiform() // Create noise that can be used to randomly drop observations from the data
g surgery_type = rbinomial(3, .375) // Create the 4 category variable that you mentioned in your email
drop if noise<=.32 // Drop some observations randomly
drop noise // Drop the variable used to randomly select observations to drop
histogram surgery_type, discrete by(year, total col(12)) // What you originally sent
histogram year, discrete by(surgery_type, col(4)) frequency // Another way of illustrating things
g cnt=1 // Create a constant that can be used to capture the frequency of events
gr bar (count) cnt, asyvars over(year) by(surgery_type, col(4)) // Different colors for each year
gr bar (count) cnt, asyvars over(surgery_type) by(year, col(12)) // Different colors for each surgical type
On Sep 24, 2013, at 11:18 AM, 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/