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

st: RE: Re: Marker labels with background color


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: RE: Re: Marker labels with background color
Date   Tue, 1 Feb 2005 19:57:24 -0600

Friedrich,

The -round()- function inside the text() option will almost give you what
you want.  For some reason, -round(le_male[`i'],.1)- for the year 1922 gives
"54.40000000000001" rather than 54.4, hence the use of -tostring- for
le_male.


#delimit ;
sysuse uslifeexp, clear;
keep if year>1918 & year<1925;

tostring le_m , gen(lem2) format(%3.1f) force;

forv i = 1/6 { ;
  local tbox "`tbox' text(`=le[`i']' `=year[`i']+0.05'
    "`=round(le[`i'],.1)'", box bc(white) place(e) size(small))";

  *local mbox "`mbox' text(`=le_male[`i']-0.2' `=year[`i']'
    "`=round(le_male[`i'],.1)'", box bc(white) place(s) size(small))";

  local mbox "`mbox' text(`=le_male[`i']-0.2' `=year[`i']'
    "`=lem2[`i']'", box bc(white) place(s) size(small))";

  local fbox "`fbox' text(`=le_female[`i']+0.2' `=year[`i']'
    "`=round(le_female[`i'],.1)'", 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));


Hope this helps,

Scott

> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Friedrich Huebler
> Sent: Tuesday, February 01, 2005 5:14 PM
> To: [email protected]
> Subject: st: Re: Marker labels with background color
> 
> 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
> 


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