Data visualization with SAS programming

Selecting colours for plot lines by grouping variable

Accepted Solution Solved
Reply
Contributor
Posts: 57
Accepted Solution

Selecting colours for plot lines by grouping variable

Hello,

I have the following syntax:

proc gplot data=DM_Work.All_Rates;

plot ir*time=testrx / vaxis = axis1 haxis=axis2

legend=legend1;

run;

I would like to specify the colour for the grouping variable TestRX.  TestRX groups treated  v untreated.  I am not sure how to make one line blue and one line red.

Any help with the syntax would be greatly appreciated.


Accepted Solutions
Solution
‎05-14-2015 09:32 AM
Contributor
Posts: 57

Re: Selecting colours for plot lines by grouping variable

Hi do you know if It is possible to combine my proc template and the macro ?

proc template;

  define style myfont;

  parent=styles.default;

   style GraphFonts /

           'GraphFootnoteFont' = ("Arial",10pt,bold)

         'GraphTitleFont' = ("Arial",6pt,bold)

         'GraphValueFont' = ("Arial",8pt)

   'GraphAnnoFont' =("Arial", 10pt)

          'GraphUnicodeFont'=("Arial", 10pt)

          'GraphLabelFont'=("Arial", 10pt)

          'GraphDataFont'=("Arial", 10pt);

   end;

run;

and

%modstyle(

parent=statistical,

name=plotmod,

type=CLM,

colors=red blue,

fillcolors=colors,

markers=triangefilled circlefilled

);

View solution in original post


All Replies
Esteemed Advisor
Esteemed Advisor
Posts: 7,190

Re: Selecting colours for plot lines by grouping variable

Move over to using proc sgplot and proc template, they will give you more controll over your output:

35864 - Change line colors and styles for PROC SGPLOT output

Grand Advisor
Posts: 10,196

Re: Selecting colours for plot lines by grouping variable

If you want to continue to use GPLOT then the statement that provides control over lines and markers is SYMBOL.

Symbol1 color=red I=join;

symbol2 color=blue I=join;

Place these before the gplot statement.

The first value of TestRX encountered will get the characteristics set in the first symbol statement.

Contributor
Posts: 57

Re: Selecting colours for plot lines by grouping variable

Hi I decided et go with Sgplot and use the code below:

proc sgplot data=DM_Work.All_Rates;

         series x=TIME y=IR / group=TestRx markers lineattrs=(pattern=solid ) ;

           REFLINE 1 2 3 4  ;

   XAXIS TYPE = DISCRETE;
   yaxis label = 'AMI Rate per 1000' ;

           xaxis label = 'Time in Days ' grid values = (-360 to 360 by 30);

run

However I want to change the markers so they are filled triangle and filled Circle.  How do I do this when using the group = option ?

Many thanks in advance.

Lucy

Super Contributor
Posts: 252

Re: Selecting colours for plot lines by grouping variable

Hi Lucy, what version of SAS have you got?

Thanks.

Contributor
Posts: 57

Re: Selecting colours for plot lines by grouping variable

9.2.

I am also trying to figure out how to get minor tick marks on the horizontal axis and rotate the label on the vertical access.

Many thanks in advance, SAS graph is new to me Smiley Happy

Esteemed Advisor
Esteemed Advisor
Posts: 7,190

Re: Selecting colours for plot lines by grouping variable

Your best bet is to have a look through Sanjay's blog at:

http://blogs.sas.com/content/graphicallyspeaking/

He has working examples for most versions of pretty much everything graph wise.  Its better than the documentation.

Super Contributor
Posts: 252

Re: Selecting colours for plot lines by grouping variable

Because you have SAS 9.2, I would use the %modstyle macro to change your markers. Such as this below:

%modstyle(

parent=statistical,

name=plotmod,

type=CLM,

colors=red blue,

fillcolors=colors,

markers=triangefilled circlefilled

);

You can then call the updated template by using ods listling style = plotmod; (or even ods html style = plotmodSmiley Wink before your Proc SGPLOT.

For documentation on the %modstyle macro go to here:

SAS/STAT(R) 9.22 User's Guide

I thought the tickmarks and ticklabels would automatically be in the format you wanted them?

Contributor
Posts: 57

Re: Selecting colours for plot lines by grouping variable

great thank you for your help.  I wanted to use minor tickmarks on the horizontal axis and offset the graoh slighty on the left so there was some space between the  graph and the border but I am unsure how to do this.  In terms of the label on the vertical axess i would like to rotate it 90 degrees but again am unsure of the syntax.I will take a look at the blog mentioned above to see if I can find the answer.  thank you again for all your help.

Solution
‎05-14-2015 09:32 AM
Contributor
Posts: 57

Re: Selecting colours for plot lines by grouping variable

Hi do you know if It is possible to combine my proc template and the macro ?

proc template;

  define style myfont;

  parent=styles.default;

   style GraphFonts /

           'GraphFootnoteFont' = ("Arial",10pt,bold)

         'GraphTitleFont' = ("Arial",6pt,bold)

         'GraphValueFont' = ("Arial",8pt)

   'GraphAnnoFont' =("Arial", 10pt)

          'GraphUnicodeFont'=("Arial", 10pt)

          'GraphLabelFont'=("Arial", 10pt)

          'GraphDataFont'=("Arial", 10pt);

   end;

run;

and

%modstyle(

parent=statistical,

name=plotmod,

type=CLM,

colors=red blue,

fillcolors=colors,

markers=triangefilled circlefilled

);

Super Contributor
Posts: 252

Re: Selecting colours for plot lines by grouping variable

Hi Lucy,

Yes you can combine the proc template and the %modstyle macro by using parent=myfont in the %modstyle macro, which will reference the template that you have created instead of the STATISTICAL style.

Okay yes, I will try to look at your other questions later if you haven't found a solution by then.

Thanks.

PS you could have also changed the colours of your groups solely by using Proc Template too.

Contributor
Posts: 57

Re: Selecting colours for plot lines by grouping variable

great thank you.

Super Contributor
Posts: 252

Re: Selecting colours for plot lines by grouping variable

That's fine. Can you please mark some of the responses to your questions as Correct Answers or Helpful Answers were appropriate?

☑ This topic is SOLVED.

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

Discussion stats
  • 12 replies
  • 664 views
  • 6 likes
  • 4 in conversation