Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: AW: AW: RE: re: Possible to have different colours for by() groups in histogram?


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: AW: RE: re: Possible to have different colours for by() groups in histogram?
Date   Wed, 4 Nov 2009 14:18:02 +0100

<> 



In fact, there is a Stata tip by Nick
http://www.stata-journal.com/sjpdf.html?articlenum=gr0023 where -separate-
was advocated for a similar problem. Probably where I got the technique from
in the first place.

On the occasion of this thread, is it policy in the Stata manuals to provide
references not cited in the main text? Kit Baum`s programming book
http://www.stata-press.com/books/isp.html  is certainly a very good source
for Stata users, and does indeed contain two references to -separate-, but I
do not see a citation in the text to it. Nick`s tip mentioned above probably
deserves a place there as well...



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Martin Weiss
Gesendet: Mittwoch, 4. November 2009 13:49
An: statalist@hsphsun2.harvard.edu
Betreff: st: AW: RE: re: Possible to have different colours for by() groups
in histogram?


<> 


Thanks for the flowers! How about the -separate- trick, then? (Fishing for
compliments, I know...)



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Nick Cox
Gesendet: Mittwoch, 4. November 2009 13:49
An: statalist@hsphsun2.harvard.edu
Betreff: st: RE: re: Possible to have different colours for by() groups in
histogram?

Thanks for this. The trick Martin used in his replies to your original
of putting frequently used options in a local macro deserves emphasis.
With not 2 but 3, 4, ... groups it becomes especially valuable. 

local opts discrete freq gap(5) xla(1/5) 

twoway histogram ease if group==1, color(red) `opts'  
|| histogram ease if group==2, color(blue) `opts' by(group, legend(off))

Nick 
n.j.cox@durham.ac.uk 

Philip Jones

Many thanks for the help Nick! That works perfectly. 

For others who may be searching about this question, it seems like you  
only need to include by(group) once in the command (with or without  
turning off the legend). Just a small point I found out running the  
command both ways.

n.j.cox@durham.ac.uk

>> . twoway histogram ease if group==1, color(red) gap(5) discrete freq
>> by(group) ///
>> || histogram ease if group == 2, color(blue) by(group, legend(off))
>> discrete freq xla(1/5)  gap(5)

Philip Jones

> I would like to know if it is possible in Stata to have different
> colours for plots in histograms created using the by() option. For
> instance, if I would like to plot frequencies of a Likert scale about
> the ease of a process (from 1 to 5) in two separate groups, I can
> generate a nice histogram using the by() option, but both "sides" (or
> plots) of the graph are the same colour.
>
> For instance,
>
> input group ease
> 1 1
> 1 2
> 1 3
> 1 3
> 1 3
> 1 3
> 1 4
> 1 5
> 1 5
> 2 2
> 2 2
> 2 2
> 2 3
> 2 3
> 2 4
> 2 4
> 2 5
> 2 5
> end
> graph twoway histogram ease, by(group) discrete frequency xtick(1(1)5)
> xlabel(1(1)5) gap(5) color(red)
>
> This gives me a histogram, but I would like a different colour for  
> each
> plot - say red for the plot on the left and blue for the one on the
> right.
>
> I am sure there is a trivial way of achieving this, but I haven't been
> able to find it. The barlook_options are not valid for histograms, and
> using the graph editor to alter the colour also results in both plots
> becoming the same colour.

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


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index