Quantcast

xtline: options for line color

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

xtline: options for line color

alison.drake
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: [hidden email]



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: xtline: options for line color

Scott Merryman
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"))

Scott




On Tue, Jul 20, 2010 at 3:40 PM, Alison Drake <[hidden email]> 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: [hidden email]

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: xtline: options for line color

Martin Weiss-5
In reply to this post by alison.drake

<>

You may want to rephrase your question in terms of an example that is within
reach of Statalist users:


***********
sysuse xtline1, clear
xtline calories, overlay
***********

Scheme "sj" is black and white, so I do not understand how one could change
the "color" of a line in there...

HTH
Martin

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Alison Drake
Sent: Dienstag, 20. Juli 2010 22:41
To: [hidden email]
Subject: st: xtline: options for line color

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: [hidden email]



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: xtline: options for line color

alison.drake
In reply to this post by alison.drake
I tried the plotline option (suggested by Scott) but I got an error saying "too many options".  I think because I have 150 ID's, so I would have to individually overlay 150 plots.  This doesn't seem to be a problem with just the xtline command with an overlay option, but is with the plot() option.

The individual plot() commands are cumbersome since I have so many groups, and I think I might have the "too many options" problem I encountered with the loop.

I have also been digging deeper into the archives and tried to use the linkplot, but can't find a way to get separate colors for different groups.  Below please find a subset of my data below for additional reference:

Essentially, I want every id to have it's own line graphed, but the color should vary based on the group variable (all group 0 are blue, group 1=red, for example).  The visit is my time variable and vl is my yvariable.  As you can see, the data is set up in long format, but I also have it in wide.

Any other suggestions on how to do this?
Thanks,
Alison

group visit vl     id
0 0 5.221649 1
0 1 4.686413 1
1 0 5.174583 2
1 1 4.065019 2
1 0 2.720159 3
1 1 2.09691 3
1 0 4.345472 4
1 1 3.639984 4
1 0 4.234644 5
1 1 3.279895 5
1 0 2.09691 7
1 1 2.09691 7
1 0 3.385606 8
1 1 3.557507 8
1 0 4.165541 9
1 1 4.279781 9
1 0 3.987666 10
1 1 3.469085 10
1 0 4.307924 11
1 1 3.472756 11
0 0 5.521073 14
0 1 4.902003 14

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Re: xtline: options for line color

Martin Weiss-5

<>

You could also build this from scratch as a -twoway line-, I think, using
Scott`s techniques...


HTH
Martin


-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of alison.drake
Sent: Mittwoch, 21. Juli 2010 22:59
To: [hidden email]
Subject: st: Re: xtline: options for line color

I tried the plotline option (suggested by Scott) but I got an error saying
"too many options".  I think because I have 150 ID's, so I would have to
individually overlay 150 plots.  This doesn't seem to be a problem with just
the xtline command with an overlay option, but is with the plot() option.

The individual plot() commands are cumbersome since I have so many groups,
and I think I might have the "too many options" problem I encountered with
the loop.

I have also been digging deeper into the archives and tried to use the
linkplot, but can't find a way to get separate colors for different groups.
Below please find a subset of my data below for additional reference:

Essentially, I want every id to have it's own line graphed, but the color
should vary based on the group variable (all group 0 are blue, group 1=red,
for example).  The visit is my time variable and vl is my yvariable.  As you
can see, the data is set up in long format, but I also have it in wide.

Any other suggestions on how to do this?
Thanks,
Alison

group visit vl     id
0 0 5.221649 1
0 1 4.686413 1
1 0 5.174583 2
1 1 4.065019 2
1 0 2.720159 3
1 1 2.09691 3
1 0 4.345472 4
1 1 3.639984 4
1 0 4.234644 5
1 1 3.279895 5
1 0 2.09691 7
1 1 2.09691 7
1 0 3.385606 8
1 1 3.557507 8
1 0 4.165541 9
1 1 4.279781 9
1 0 3.987666 10
1 1 3.469085 10
1 0 4.307924 11
1 1 3.472756 11
0 0 5.521073 14
0 1 4.902003 14


--
View this message in context:
http://statalist.1588530.n2.nabble.com/xtline-options-for-line-color-tp53184
43p5322903.html
Sent from the Statalist mailing list archive at Nabble.com.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Re: xtline: options for line color

Scott Merryman
In reply to this post by alison.drake
Something like this:

clear
set obs 150
gen id = _n
expand 30
bys id: gen t = _n
gen group = (id<=75)
gen x = rnormal() if gr == 0
replace x = rnormal(4,1) if gr == 1
forv i = 1/150 {
        if `i' < 76 {
                local plotline1  "`plotline1' line x t if id == `i', lc(black)  || "
        }
        else {
                local plotline2  "`plotline2' line x t if id == `i', lc(blue) || "
        }
}
 twoway `plotline1' `plotline2' , legend(order(1 "Group 1" 76 "Group 2"))


Scott


On Wed, Jul 21, 2010 at 4:15 PM, Martin Weiss <[hidden email]> wrote:

>
> <>
>
> You could also build this from scratch as a -twoway line-, I think, using
> Scott`s techniques...
>
>
> HTH
> Martin
>
>
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of alison.drake
> Sent: Mittwoch, 21. Juli 2010 22:59
> To: [hidden email]
> Subject: st: Re: xtline: options for line color
>
> I tried the plotline option (suggested by Scott) but I got an error saying
> "too many options".  I think because I have 150 ID's, so I would have to
> individually overlay 150 plots.  This doesn't seem to be a problem with just
> the xtline command with an overlay option, but is with the plot() option.
>
> The individual plot() commands are cumbersome since I have so many groups,
> and I think I might have the "too many options" problem I encountered with
> the loop.
>
> I have also been digging deeper into the archives and tried to use the
> linkplot, but can't find a way to get separate colors for different groups.
> Below please find a subset of my data below for additional reference:
>
> Essentially, I want every id to have it's own line graphed, but the color
> should vary based on the group variable (all group 0 are blue, group 1=red,
> for example).  The visit is my time variable and vl is my yvariable.  As you
> can see, the data is set up in long format, but I also have it in wide.
>
> Any other suggestions on how to do this?
> Thanks,
> Alison
>
> group   visit   vl           id
> 0       0       5.221649        1
> 0       1       4.686413        1
> 1       0       5.174583        2
> 1       1       4.065019        2
> 1       0       2.720159        3
> 1       1       2.09691 3
> 1       0       4.345472        4
> 1       1       3.639984        4
> 1       0       4.234644        5
> 1       1       3.279895        5
> 1       0       2.09691 7
> 1       1       2.09691 7
> 1       0       3.385606        8
> 1       1       3.557507        8
> 1       0       4.165541        9
> 1       1       4.279781        9
> 1       0       3.987666        10
> 1       1       3.469085        10
> 1       0       4.307924        11
> 1       1       3.472756        11
> 0       0       5.521073        14
> 0       1       4.902003        14
>
>
> --
> View this message in context:
> http://statalist.1588530.n2.nabble.com/xtline-options-for-line-color-tp53184
> 43p5322903.html
> Sent from the Statalist mailing list archive at Nabble.com.
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

AW: st: RE: Re: xtline: options for line color

Martin Weiss-5

<>



As Scott`s example code shows quite clearly, 150 IDs and their respective
lines on _one_ graph may not make for a clear picture. Alison may want to
spread them over several graphs...

HTH
Martin

-----Ursprüngliche Nachricht-----
Von: [hidden email]
[mailto:[hidden email]] Im Auftrag von Scott Merryman
Gesendet: Donnerstag, 22. Juli 2010 03:32
An: [hidden email]
Betreff: Re: st: RE: Re: xtline: options for line color

Something like this:

clear
set obs 150
gen id = _n
expand 30
bys id: gen t = _n
gen group = (id<=75)
gen x = rnormal() if gr == 0
replace x = rnormal(4,1) if gr == 1
forv i = 1/150 {
        if `i' < 76 {
                local plotline1  "`plotline1' line x t if id == `i',
lc(black)  || "
        }
        else {
                local plotline2  "`plotline2' line x t if id == `i',
lc(blue) || "
        }
}
 twoway `plotline1' `plotline2' , legend(order(1 "Group 1" 76 "Group 2"))


Scott


On Wed, Jul 21, 2010 at 4:15 PM, Martin Weiss <[hidden email]> wrote:

>
> <>
>
> You could also build this from scratch as a -twoway line-, I think, using
> Scott`s techniques...
>
>
> HTH
> Martin
>
>
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of alison.drake
> Sent: Mittwoch, 21. Juli 2010 22:59
> To: [hidden email]
> Subject: st: Re: xtline: options for line color
>
> I tried the plotline option (suggested by Scott) but I got an error saying
> "too many options".  I think because I have 150 ID's, so I would have to
> individually overlay 150 plots.  This doesn't seem to be a problem with
just
> the xtline command with an overlay option, but is with the plot() option.
>
> The individual plot() commands are cumbersome since I have so many groups,
> and I think I might have the "too many options" problem I encountered with
> the loop.
>
> I have also been digging deeper into the archives and tried to use the
> linkplot, but can't find a way to get separate colors for different
groups.
> Below please find a subset of my data below for additional reference:
>
> Essentially, I want every id to have it's own line graphed, but the color
> should vary based on the group variable (all group 0 are blue, group
1=red,
> for example).  The visit is my time variable and vl is my yvariable.  As
you

> can see, the data is set up in long format, but I also have it in wide.
>
> Any other suggestions on how to do this?
> Thanks,
> Alison
>
> group   visit   vl           id
> 0       0       5.221649        1
> 0       1       4.686413        1
> 1       0       5.174583        2
> 1       1       4.065019        2
> 1       0       2.720159        3
> 1       1       2.09691 3
> 1       0       4.345472        4
> 1       1       3.639984        4
> 1       0       4.234644        5
> 1       1       3.279895        5
> 1       0       2.09691 7
> 1       1       2.09691 7
> 1       0       3.385606        8
> 1       1       3.557507        8
> 1       0       4.165541        9
> 1       1       4.279781        9
> 1       0       3.987666        10
> 1       1       3.469085        10
> 1       0       4.307924        11
> 1       1       3.472756        11
> 0       0       5.521073        14
> 0       1       4.902003        14
>
>
> --
> View this message in context:
>
http://statalist.1588530.n2.nabble.com/xtline-options-for-line-color-tp53184

> 43p5322903.html
> Sent from the Statalist mailing list archive at Nabble.com.
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Re: xtline: options for line color

alison.drake
In reply to this post by Scott Merryman

Thanks so much this worked!

 

From: Scott Merryman [via Statalist] [mailto:[hidden email]]
Sent: Wednesday, July 21, 2010 6:33 PM
To: alison.drake
Subject: RE: Re: xtline: options for line color

 

Something like this:

clear
set obs 150
gen id = _n
expand 30
bys id: gen t = _n
gen group = (id<=75)
gen x = rnormal() if gr == 0
replace x = rnormal(4,1) if gr == 1
forv i = 1/150 {
        if `i' < 76 {
                local plotline1  "`plotline1' line x t if id == `i', lc(black)  || "
        }
        else {
                local plotline2  "`plotline2' line x t if id == `i', lc(blue) || "
        }
}
 twoway `plotline1' `plotline2' , legend(order(1 "Group 1" 76 "Group 2"))


Scott


On Wed, Jul 21, 2010 at 4:15 PM, Martin Weiss <[hidden email]> wrote:


>
> <>
>
> You could also build this from scratch as a -twoway line-, I think, using
> Scott`s techniques...
>
>
> HTH
> Martin
>
>
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of alison.drake
> Sent: Mittwoch, 21. Juli 2010 22:59
> To: [hidden email]
> Subject: st: Re: xtline: options for line color
>
> I tried the plotline option (suggested by Scott) but I got an error saying
> "too many options".  I think because I have 150 ID's, so I would have to
> individually overlay 150 plots.  This doesn't seem to be a problem with just
> the xtline command with an overlay option, but is with the plot() option.
>
> The individual plot() commands are cumbersome since I have so many groups,
> and I think I might have the "too many options" problem I encountered with
> the loop.
>
> I have also been digging deeper into the archives and tried to use the
> linkplot, but can't find a way to get separate colors for different groups.
> Below please find a subset of my data below for additional reference:
>
> Essentially, I want every id to have it's own line graphed, but the color
> should vary based on the group variable (all group 0 are blue, group 1=red,
> for example).  The visit is my time variable and vl is my yvariable.  As you
> can see, the data is set up in long format, but I also have it in wide.
>
> Any other suggestions on how to do this?
> Thanks,
> Alison
>
> group   visit   vl           id
> 0       0       5.221649        1
> 0       1       4.686413        1
> 1       0       5.174583        2
> 1       1       4.065019        2
> 1       0       2.720159        3
> 1       1       2.09691 3
> 1       0       4.345472        4
> 1       1       3.639984        4
> 1       0       4.234644        5
> 1       1       3.279895        5
> 1       0       2.09691 7
> 1       1       2.09691 7
> 1       0       3.385606        8
> 1       1       3.557507        8
> 1       0       4.165541        9
> 1       1       4.279781        9
> 1       0       3.987666        10
> 1       1       3.469085        10
> 1       0       4.307924        11
> 1       1       3.472756        11
> 0       0       5.521073        14
> 0       1       4.902003        14
>
>
> --
> View this message in context:
> http://statalist.1588530.n2.nabble.com/xtline-options-for-line-color-tp53184
> 43p5322903.html
> Sent from the Statalist mailing list archive at Nabble.com.
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


View message @ http://statalist.1588530.n2.nabble.com/xtline-options-for-line-color-tp5318443p5323657.html
To unsubscribe from Re: xtline: options for line color, click here.

 

Loading...