Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: More subtle use of by-plots


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: More subtle use of by-plots
Date   Fri, 23 Nov 2007 18:38:12 -0000

In addition to this useful trick, similar effects are often 
possible without changing the data, even temporarily. 

scatter mpg price, by(foreign) || scatter mpg price if mpg == 41,
ms(none) mla(make)legend(off)

will add a marker label in just one panel.  

Nick
[email protected] 

Paul Seed

"Vladimir V. Dashkeyev" <[email protected]> and "David Elliott"
<[email protected]> have both recently asked questions relating to
axes and arrows when using overlaid graphs and bygraphs, to which
various solutions have been offered.

I have been working with a related problem: to add text to one only of a
series of by-graphs.
Any attempt to use titles or textboxes is replicated across all graphs.

The solution I eventually found was for each piece of text to first
create an extra observation, related to only one category, and then
generate new variables containing the details to be revealed.
Then use -scatter- to plot  invisible points with appropriate text.

clear
sysuse auto
local n = _N +1
set obs `n'
gen y1 = 35 in _N
gen x1 = 10000 in _N
gen star = "***" in _N

recode for . = 1

twoway ///
(scatter mpg price ) ///
(scatter y1 x1 , mlab(star) mlabsize(huge)  ms(i) ) /// , by(for)

  This approach will also work for adding arrows, using -pcarrow-:

gen y2 = 20 if _n == _N
gen x2 = 8000 if _n == _N
twoway ///
(scatter mpg price ) ///
(pcarrow y1 x1 y2 x2 ,  ) ///
, by(for)

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