Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: xtline: options for line color

From   Scott Merryman <>
Subject   Re: st: xtline: options for line color
Date   Tue, 20 Jul 2010 16:01:31 -0500

You have to use the -plot#()- option when using the -overlay- option.

For example:

webuse grunfeld, clear
gen lninvest = ln(invest)
xtline lninvest , overlay plot1(lc(blue)) plot2(lc(blue))
plot3(lc(blue)) plot4(lc(blue)) plot5(lc(blue))

Or you could use locals to gather up the plot#() options:

//Group 1, companies 1-5; Group 2 companies 6-10
forv i = 1/10 {
	if `i' < 6 {
		local plotline1  "`plotline1' plot`i'(lc(blue)) "
	else {
		local plotline2 "`plotline2' plot`i'(lc(black)) "
xtline lninvest, overlay `plotline1' `plotline2' legend(order(1 "Group
1" 6 "Group 2"))


On Tue, Jul 20, 2010 at 3:40 PM, Alison Drake <> wrote:
> I would like to change the color of lines for subgroups on a graph generated
> by xtline.  I want to create an overlay of the lines by 2 different groups,
> group 0 and 1 and have the lines for group 0 be one color and group 1 be
> another color.  Currently, I can’t figure out how to change the line options
> unless I use a scheme, and I haven’t been able to adjust the line options by
> groups.
> The code I am using now (which I have also added 2 lowess curves to) shows
> the plasmaVL for each id using the sj scheme color (see below).  Can anyone
> help me get different colors of lines by group? Instead of scheme(sj) I have
> tried lcolor (green) to try to adjust the color for all, as well as lcolor
> if group==0 or if group==1 without success.  I’m not sure this is possible
> with xtline…
> xtset idno visitno
> xtline plasmaVL,   overlay legend(off) scheme(sj) xlabel(0(1)1)
> title("Plasma HIV viral load over time, by treatment group")  ytitle("Log10
> copies/mL") /*
> */ xtitle("Visit number")  addplot ((lowess plasmaVL visitno if group==0,
> lcolor(blue) lpattern(solid) lwidth(thick))/*
> */(lowess plasmaVL visitno if group==1, lcolor(red) lpattern(solid)
> lwidth(thick)))
> Thanks,
> Alison Drake, MPH
> Pre-doctoral Fellow
> Department of Epidemiology
> University of Washington
> Box 359909
> Seattle, WA 98195-7236
> phone: (206) 579-9211
> email:

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index