
From  "MA V" <[email protected]> 
To  [email protected] 
Subject  Re: st: adding lines to multiple histograms  revisited  
Date  Wed, 24 Jan 2007 21:51:05 +0000 
From: n j cox <[email protected]>_________________________________________________________________
ReplyTo: [email protected]
To: [email protected]
Subject: Re: st: adding lines to multiple histograms  revisited 
Date: Wed, 24 Jan 2007 21:05:21 +0000
This is a repost of a question asked earlier.
Two answers followed this: both made broad suggestions
about combining different graphs, but neither
focused on the key question, as one person made
clear.
As has happened before, the earlier post was
already answered with precise code.
That answer is in the archives at
http://www.hsph.harvard.edu/cgibin/lwgate/STATALIST/archives/statalist.0701/date/article770.html
or
http://www.stata.com/statalist/archive/200701/msg00778.html
V MA, or MA V: There is something inefficient about
your processing of Statalist. If you have an erratic email
connection, I recommend a thorough scan of the archives
before reposting. All this advice is in the FAQ or implicit
therein.
Cycling around the same question makes Statalist unnecessarily
repetitive and causes small problems for everyone.
Nick
[email protected]
MA V
I am drawing multiple histograms in one plot by using the "by" option.
e.g. hist age, by(city)
(note: I have 15 cities)
My question was the following: is it possible to add one vertical line to
each individual histogram(note that these lines have different values for
different cities, i.e. for different histograms)?
Nick suggested that I superimpose a spike plot to each histogram in order to
achieve the desired effect by doing the following:
sysuse auto, clear
*Suppose we want our lines at the positions of the means.
egen mean = mean(mpg), by(rep78)
*A first histogram gives us an idea of how high we want the lines to go.
twoway histogram mpg, by(rep78)
gen max = 0.2
*Then superimpose a spike plot on the histograms.
twoway histogram mpg  spike max mean,
by(rep78, legend(off)) yti(Density) xti(Miles per gallon)
This works fine BUT in my case I am ploting 15 different histograms in the
same plot and picking a different "max" for each one of them is not really
practical. Also, I'm using the rescaling option for both the X and the Y
axes since the histograms have different scales.
I was wondering if there is a way of telling Stata that the height of each
of the lines (one for each histogram) should be a function of the histogram
itself. For example, can we somehow specify that each spike should be as
high as the highest bar in each of the histograms? Note: I am plotting
densitybased histograms.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
© Copyright 1996–2024 StataCorp LLC  Terms of use  Privacy  Contact us  What's new  Site index 