Statalist


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

Re: st: weighted scatter / different label size


From   "Friedrich Huebler" <[email protected]>
To   [email protected]
Subject   Re: st: weighted scatter / different label size
Date   Fri, 19 Oct 2007 11:41:10 -0400

You can save yourself some typing by building up the -scatter- command
in a loop.

sysuse auto, clear
egen labcat = cut(price), group(10)
qui centile price
local median = r(c_1)
forvalues i = 0/9 {
  qui centile price if labcat == `i'
  local labsize`i' = sqrt(r(c_1)/`median')
}
#delimit ;
forvalues i = 0/9 {;
  local scatter "`scatter' (scatter mpg weight if labcat==`i',
 msymbol(i) mlabel(make) mlabp(0) mlabsize(*`labsize`i''))";
};
#delimit cr
twoway `scatter', legend(off)

Friedrich


On 10/19/07, Philipp Rehm <[email protected]> wrote:
> Maarten,
>
> many thanks - that's a very nice work-around!
>
> Thanks again,
> Philipp
>
> Maarten buis wrote:
> > --- Philipp Rehm <[email protected]> wrote:
> >> I would like to produce a scatter plot in which the labels are
> >> "weighted", i.e. are proportional to the size of what they indicate.
> >
> > You can control the size of a label using the -mlabsize()- option, and
> > you can use that to make the kind of graph you want. See the example
> > below. Problem with these graphs is that the labels pretty soon become
> > illegible due to small size or overplotting.
> >
> > *------------- begin example ---------------
> > sysuse auto, clear
> > egen labcat = cut(pri), group(10)
> > qui centile pri
> > local median = r(c_1)
> > forvalues i = 0 / 9 {
> >       qui centile pri if labcat == `i'
> >       local labsize`i' = sqrt(r(c_1)/`median')
> > }
> > twoway scatter mpg wei if labcat == 0,           /*
> >             */ msymbol(i) mlabel(make)           /*
> >             */ mlabp(0) mlabsize(*`labsize0') || /*
> >     */ scatter mpg wei if labcat == 1,           /*
> >             */ msymbol(i) mlabel(make)           /*
> >             */ mlabp(0) mlabsize(*`labsize1') || /*
> >     */ scatter mpg wei if labcat == 2,           /*
> >             */ msymbol(i) mlabel(make)           /*
> >             */ mlabp(0) mlabsize(*`labsize2') || /*
> >     */ scatter mpg wei if labcat == 3,           /*
> >             */ msymbol(i) mlabel(make)           /*
> >             */ mlabp(0) mlabsize(*`labsize3') || /*
> >     */ scatter mpg wei if labcat == 4,           /*
> >             */ msymbol(i) mlabel(make)           /*
> >             */ mlabp(0) mlabsize(*`labsize4') || /*
> >     */ scatter mpg wei if labcat == 5,           /*
> >             */ msymbol(i) mlabel(make)           /*
> >             */ mlabp(0) mlabsize(*`labsize5') || /*
> >     */ scatter mpg wei if labcat == 6,           /*
> >             */ msymbol(i) mlabel(make)           /*
> >             */ mlabp(0) mlabsize(*`labsize6') || /*
> >     */ scatter mpg wei if labcat == 7,           /*
> >             */ msymbol(i) mlabel(make)           /*
> >             */ mlabp(0) mlabsize(*`labsize7') || /*
> >     */ scatter mpg wei if labcat == 8,           /*
> >             */ msymbol(i) mlabel(make)           /*
> >             */ mlabp(0) mlabsize(*`labsize8') || /*
> >     */ scatter mpg wei if labcat == 9,           /*
> >             */ msymbol(i) mlabel(make)           /*
> >             */ mlabp(0) mlabsize(*`labsize9')    /*
> >             */ legend(off)
> > *------------------ end example ---------------------
> > (For more on how to use examples I sent to the Statalist, see
> > http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )
> >
> > Hope this helps,
> > Maarten
> >
> >
> > -----------------------------------------
> > Maarten L. Buis
> > Department of Social Research Methodology
> > Vrije Universiteit Amsterdam
> > Boelelaan 1081
> > 1081 HV Amsterdam
> > The Netherlands
> >
> > visiting address:
> > Buitenveldertselaan 3 (Metropolitan), room Z434
> >
> > +31 20 5986715
> >
> > http://home.fsw.vu.nl/m.buis/
> > -----------------------------------------
*
*   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