Statalist


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

st: RE: hist with addplot option


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: hist with addplot option
Date   Tue, 25 Nov 2008 21:17:45 -0000

I confirm problems with putting one -histogram- on top of another. 

However, I can get -twoway histogram- to play: 

sysuse auto 

twoway histogram mpg if !foreign, ///
start(10) width(2) freq bfcolor(none) blcolor(pink)  ///
|| histogram mpg if foreign, freq start(10) width(2) barw(1.8) ///
bfcolor(none) blcolor(blue) ///
legend(order(1 "Domestic" 2 "Foreign") pos(2) ring(0) col(1))

A small tip inside that example is tweaking the -barwidth()- of one
display so that one set of bars just fits inside another. Like it or
loathe it, it's a possibility. 

The answer to Murali's question about colours is: Look at the -help- to
find out about the options! 

That said, these superimposed histograms are Statistics 100 graphics.
It's difficult to avoid a small mess often and a large mess even more
often. Artefacts of bin width and origin abound unchecked even if you
think about them. 

Beyond that, what happens when you have not just two groups but several?


With no apologies for all the plugs, consider some other ways of
comparing two distributions: 

Official: 

-qqplot- (although this is limited to two groups also) 
-dotplot- 
-kdensity- (cf. David Airey's suggestion) 

User-written:

-distplot- (SJ) 
-qplot- (SJ) 
-stripplot, stack- (SSC) 
-beamplot- (SSC) 

... and others. 

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

Murali Kuchibhotla

      I am trying to plot 2 histograms on the same graph using the
addplot 
option as follows:

hist  math_grade if  MATH_cat==2 &  course=="econ_10", addplot(hist  
math_grade if  MATH_cat==2 &  course=="psych_101") freq addl

However, when I run this I get the same graph as when I run:

hist  math_grade if  MATH_cat==2 &  course=="econ_10",freq addl

Can someone please tell me what I am doing wrong? Also, is there a way
to 
represent the bars of the 2 histograms in different colors? Thanks.


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