Proc Gplot - How can i edit the legend variable names?

Accepted Solution Solved
Reply
Contributor
Posts: 25
Accepted Solution

Proc Gplot - How can i edit the legend variable names?

Dear SAS community,

I have performed data analysis with variable using Gplot. Here is an example of how the data looks like

goptions reset=all border;

option linesize=80;

Data peter;

Input Species$    Sex$    Length    diam    Vulvadiam    vulanuslength    v    anusdiam    Styletlength    stbdiam    stbulbhigh    Po    AesophaL    PUS    Tail    V    ra    rb    rc    rcprime;

Cards;

A    Male    1040.00    40.00    .    .    .    30.00    11.50    1.00    1.00    170.00    200.00    .    60.00    .    26.00    6.12    5.20    6.67

B    Male    1150.00    40.00    .    .    .    30.00    12.50    1.00    1.00    175.00    200.00    .    70.00    .    28.75    6.57    5.75    6.67

C

..............

...............

proc gplot;

plot prin1*prin2=Species;

Since i have coded my variable name from A to H, the legend produced automatically reveals the variable names A-H. I cannot use the real variable names because the have very minor differences which SAS is not able to detect. So i am left with the choice of editing the legend to fit in my real variable names. I have struggled with several codes but without success. Could someone please kindly assist?

Secondly, i would like to have my graph without all the frame. I only want to retain the X and Y axis and get rid of the top and right axis. This will help me so so much.

Looking forward to your help.

Kind regards,

Peter


Accepted Solutions
Solution
‎11-22-2013 02:19 PM
Super User
Posts: 10,466

Re: Proc Gplot - How can i edit the legend variable names?

I am confused about your mention of variables A-H, your example doesn't show any variables of those names and they don't appear on the plot statement. The legend should have values of Species displayed. If you create a custom format and associate the variable species with that format then the formatted values should show. Labels for variables are also useful in getting prettier output in general.

Also you must be doing something else with data as you are plotting prin1 against prin2 but those don't appear in your example data.

Proc format;

value $MySpecies

'A' = 'Mountain lion'

'B' = 'Tiger'

'C' = 'Panther'

;

run;

proc gplot;

format Species $MySpecies.;

plot ....

;

run;

quit;

View solution in original post


All Replies
Solution
‎11-22-2013 02:19 PM
Super User
Posts: 10,466

Re: Proc Gplot - How can i edit the legend variable names?

I am confused about your mention of variables A-H, your example doesn't show any variables of those names and they don't appear on the plot statement. The legend should have values of Species displayed. If you create a custom format and associate the variable species with that format then the formatted values should show. Labels for variables are also useful in getting prettier output in general.

Also you must be doing something else with data as you are plotting prin1 against prin2 but those don't appear in your example data.

Proc format;

value $MySpecies

'A' = 'Mountain lion'

'B' = 'Tiger'

'C' = 'Panther'

;

run;

proc gplot;

format Species $MySpecies.;

plot ....

;

run;

quit;

Contributor
Posts: 25

Re: Proc Gplot - How can i edit the legend variable names?

Dear Ballardw,

Many thanks for the support! it actually worked very well with the Proc Format after i followed the method you proposed. Many thanks.

I have however one more further question.

After running the

Proc format;

value $MySpecies

'A' = 'Mountain lion'

'B' = 'Tiger'

'C' = 'Panther'

;

run;

proc gplot;

format Species $MySpecies.;

plot ....

;

run;

quit;

I would like to change the font of the labels in $MySpecies in to Italics since they represent a group of species. I am using the actual names such...e.g 'M. incognita''.



Addtionally, i would like to create data ellipses around individual groups of nematodes after i obtain my scatter plot from the PCA analysis.

Please see below my Proc.

Data Ddestructor;

Input MySpecies$    Species$    Sex$    Length    diam    Vulvadiam    vulanuslength    v    anusdiam    Styletlength    stbdiam    stbulbhigh    Po    AesophaL    PUS    Tail    V    ra    rb    rc    rcprime;

Cards;

D.destructor(Ger)    A    Male    1040.00    40.00    .    .    .    30.00    11.50    1.00    1.00    170.00    200.00    .    60.00    .    26.00    6.12    5.20    6.67

D.destructor(Ger)    A    Male    1150.00    40.00    .    .    .    30.00    12.50    1.00    1.00    175.00    200.00    .    70.00    .    28.75    6.57    5.75    6.67

D.destructor(Ger)    A    Male    1140.00    30.00    .    .    .    30.00    15.00    2.50    2.50    170.00    135.00    .    72.50    .    38.00    6.71    8.44    4.50

D.destructor(Ger)    A    Male    1310.00    35.00    .    .    .    22.50    10.00    1.00    3.00    170.00    132.00    .    62.50    .    37.43    7.71    9.92    5.87

...........

............

proc princomp out=prinDdestructor plots= score(ellipse ncomp=3);

id Species;

var    Length    diam    Vulvadiam    vulanuslength    v    anusdiam    Styletlength    stbdiam    stbulbhigh    Po    AesophaL    PUS    Tail    V    ra    rb    rc    rcprime;

run;

Proc format;

Value $MySpecies

'A' = 'D. destructor (Ger)'

'B' = 'D. destructor (Rus)'

'C' = 'D. destructor (Ukr)'

'D' = 'D. dipsaci (pop91)'

'E' = 'D. dipsaci (80)'

'F' = 'D. dipsaci (79)'

'G' = 'D. dipsaci (60)'

'H' = 'D. dipsaci (31)';

Run;

proc gplot;

format Species $MySpecies.;

plot prin1*prin2=Species/noframe;

Symbol1 I = None V=Dot C= Black;

Symbol2 I = None V= = C = Black;

Symbol3 I = None V= Trianglefilled C = Black;

Symbol4 I = None V= Circle C = Black;

Symbol5 I = None V= Triangle C = Black;

Symbol6 I = None V= Diamond C= Black;

Symbol7 I = None V= Square C = Black;

Symbol8 I = None V= Squarefilled C =Black;

Run;

After this i have created a PCA graph with two groups of each species. I would like to crease an ellipse around the two groups of species. I have seen this is possible with Proc sgplot (for scatter plot) but seems like this is not working for me.  Hope you can help with this.

Kind regards,

Peter

SAS Employee
Posts: 967

Re: Proc Gplot - How can i edit the legend variable names?

Per the 2nd part of your question, you can use gplot's "noframe" option:

proc gplot data=sashelp.class;

plot height*weight / noframe;

run;

Contributor
Posts: 25

Re: Proc Gplot - How can i edit the legend variable names?

Dear Robert Allison,

Many thanks for the answer. It worked.

Regards,

Peter

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 265 views
  • 1 like
  • 3 in conversation