Date: Thu, 18 Dec 2008 06:37:31 -0500
Reply-To: Nathaniel.Wooding@DOM.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Nat Wooding <Nathaniel.Wooding@DOM.COM>
Subject: Re: How to distinguish variables on a scatter plot
In-Reply-To: <d051b19c-84ae-4446-941d-6bc5fefe1654@j39g2000yqn.googlegroups.com>
Content-Type: text/plain; charset="US-ASCII"
Paul
I see that you are using Proc Plot and not Gplot. Do you have SAS/Graph
installed because if you do,you can produce much better plots.
In any case, you can do a scatter plot such as you asked for. The trick is
to have a variable whose values are the symbols that you want to plot. In
the code below, I added an IF statement that assigns an F to the females
and an M to the males. I called this variable Gender. Then I changed the
plot statement to read
Plot tlc*height = Gender;
If you are not sure about whether you have the SAS Graph package, try
changing Proc Plot to Proc Gplot and see if it works. If it does, you can
use the rest of the code that you already have and by using symbol and axis
statements, among others, produce much more sophisticated graphs.
Here is a modified version of your code.
data lung;
input patient age sex height tlc;
if sex = 0 then Gender = 'F';
else Gender = 'M';* use this for the plotting symbol;
* I have turned this off since we do not have a format defined for Sex
format sex sex.;
label
patient='Patient ID number'
age='Age in years'
sex='Sex (0=female 1=male)'
height='Height (cm)'
tlc='Total lung capacity'
;
cards;
1 35 0 149 3.40
2 11 0 138 3.41
3 12 1 148 3.80
4 16 0 156 3.90
5 32 0 152 4.00
6 16 0 157 4.10
7 14 0 165 4.46
8 16 1 152 4.55
9 35 0 177 4.83
10 33 0 158 5.10
11 40 0 166 5.44
12 28 0 165 5.50
13 23 0 160 5.73
14 52 1 178 5.77
15 46 0 169 5.80
16 29 1 173 6.00
17 30 0 172 6.30
18 21 0 163 6.55
19 21 0 164 6.60
20 20 1 189 6.62
21 34 1 182 6.89
22 43 1 184 6.90
23 35 1 174 7.00
24 39 1 177 7.20
25 43 1 183 7.30
26 37 1 175 7.65
27 32 1 173 7.80
28 24 1 173 7.90
29 20 0 162 8.05
30 25 1 180 8.10
31 22 1 173 8.70
32 25 1 171 9.45
;
run;
proc plot data=lung;
title1 'Figure 1: Total lung capacity vs height';
title2 'Low-resolution plot using default options';
plot tlc*height = Gender;* Gender added here;
run;
quit;
Nat Wooding
Environmental Specialist III
Dominion, Environmental Biology
4111 Castlewood Rd
Richmond, VA 23234
Phone:804-271-5313, Fax: 804-271-2977
Paul Lambson
<paullambson@GMAI
L.COM> To
Sent by: "SAS(r) SAS-L@LISTSERV.UGA.EDU
Discussion" cc
<SAS-L@LISTSERV.U
GA.EDU> Subject
How to distinguish variables on a
scatter plot
12/18/2008 02:17
AM
Please respond to
Paul Lambson
<paullambson@GMAI
L.COM>
I am trying to use a scatter plot graph and use two make the variables
different colors. In this example I would like the female and the male
observations to be different. Any help on this would be great.
Thanks,
Paul
proc format;
value sex
0='Females'
1='Males'
;
run;
data lung;
input patient age sex height tlc;
format sex sex.;
label
patient='Patient ID number'
age='Age in years'
sex='Sex (0=female 1=male)'
height='Height (cm)'
tlc='Total lung capacity'
;
cards;
1 35 0 149 3.40
2 11 0 138 3.41
3 12 1 148 3.80
4 16 0 156 3.90
5 32 0 152 4.00
6 16 0 157 4.10
7 14 0 165 4.46
8 16 1 152 4.55
9 35 0 177 4.83
10 33 0 158 5.10
11 40 0 166 5.44
12 28 0 165 5.50
13 23 0 160 5.73
14 52 1 178 5.77
15 46 0 169 5.80
16 29 1 173 6.00
17 30 0 172 6.30
18 21 0 163 6.55
19 21 0 164 6.60
20 20 1 189 6.62
21 34 1 182 6.89
22 43 1 184 6.90
23 35 1 174 7.00
24 39 1 177 7.20
25 43 1 183 7.30
26 37 1 175 7.65
27 32 1 173 7.80
28 24 1 173 7.90
29 20 0 162 8.05
30 25 1 180 8.10
31 22 1 173 8.70
32 25 1 171 9.45
;
run;
proc plot data=lung;
title1 'Figure 1: Total lung capacity vs height';
title2 'Low-resolution plot using default options';
plot tlc*height;
run;
quit;
CONFIDENTIALITY NOTICE: This electronic message contains
information which may be legally confidential and/or privileged and
does not in any case represent a firm ENERGY COMMODITY bid or offer
relating thereto which binds the sender without an additional
express written confirmation to that effect. The information is
intended solely for the individual or entity named above and access
by anyone else is unauthorized. If you are not the intended
recipient, any disclosure, copying, distribution, or use of the
contents of this information is prohibited and may be unlawful. If
you have received this electronic transmission in error, please
reply immediately to the sender that you have received the message
in error, and delete it. Thank you.