Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Marker labels with background color


From   Friedrich Huebler <[email protected]>
To   [email protected]
Subject   st: Re: Marker labels with background color
Date   Tue, 1 Feb 2005 15:13:38 -0800 (PST)

Scott,

Thank you for your response to my query. I like your suggestion to
use the -text(, box)- option. Below is a good example for the kind of
graph that I am actually trying to create. I have three timelines
(total, male, and female) and the points are sometimes so close to
each other that I cannot draw the labels on top of the marker. This
is solved by adding the -place()- option.

I also found that at the default position of the textbox the markers
are partially covered. My solution is to add or subtract a certain
amount from the coordinates of the marker. This amount depends on the
scale of the x- and y-axes.

I am left with one problem for which I have no solution. I would like
the labels to appear in the format %4.1f but the number 61.8, for
example, appears as 61.79999923706055 in the textbox. I tried setting
-format le le_male le_female %4.1f- but this has no effect on the
graph.

#delimit ;
sysuse uslifeexp, clear;
keep if year>1918 & year<1925;
forv i = 1/6 {;
  local tbox "`tbox' text(`=le[`i']' `=year[`i']+0.05'
    "`=le[`i']'", box bc(white) place(e) size(small))";
  local mbox "`mbox' text(`=le_male[`i']-0.2' `=year[`i']'
    "`=le_male[`i']'", box bc(white) place(s) size(small))";
  local fbox "`fbox' text(`=le_female[`i']+0.2' `=year[`i']'
    "`=le_female[`i']'", box bc(white) place(n) size(small))";
  };
scatter le year, connect(l) `tbox' ||
  scatter le_male year, connect(l) `mbox' ||
  scatter le_female year, connect(l) `fbox'
  xscale(r(1918.8 1924.2)) yscale(r(53 63));

Many thanks,

Friedrich

--- Scott Merryman <[email protected]> wrote:
> > -----Original Message-----
> > Is there a way to draw marker labels with a background color? The
> > otherwise meaningless example below shows what I am trying to
> > achieve.
> > 
> > . sysuse auto
> > . scatter mpg weight, connect(l) mlabel(mpg)
> > 
> > Most labels are difficult to read because a line runs through
> > them. Is it possible to draw the labels on top of a white square
> > so that the lines don't interfere?
> > 
> 
> Two possible solutions.
> 
> 1.  Make the lines lighter so the labels are more noticeable.
> 2.  Use the -text(, box)- option.
> 
> sysuse auto,clear
> keep in 1/70
> twoway  (connected mpg weight, msymbol(circle) msize(small) ///
>  mcolor(gs15) clcolor(gs15) clwidth(thin)) || /// 
> (scatter mpg weight, ms(i)  mlabel(mpg) mlabsize(*1.2) legend(off))
> 
> forv i = 1/70 {
> local textbox "`textbox' text(`=mpg[`i']' `=weight[`i']' "`i'" ,
> ///
> bc(white) box)" 
> }
> 
> twoway (connected mpg weight,  msize(small) clwidth(thin) `textbox'
> )
> 
> However, the -text- option seems limited to 70 boxes.


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
*
*   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