Data visualization with SAS programming

How to get multiple linestyles in same sgplot graph ?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

How to get multiple linestyles in same sgplot graph ?

I have 4 treatment groups to be displayed in the graph. I need different linestyles (solid, dashed, etc ..) for each treatment group. 

With the below code which I have written, I'm getting same linestyle for all 4.

 

How to use the linestyle option in sgplot ? Please enlighten me. I am a beginner. Thanks


proc sgplot data = final noautolegend;
xaxis label = 'Week';
yaxis label = 'Blood Pressure (mmHg)';

series x = visitname y = mean / group = trtp lineattrs = (pattern = 1) markers;
keylegend/ title = 'Treatment ';
scatter x = visitname y = mean / group = trtp yerrorlower = lower
yerrorupper = upper ;
run;

 

 

Thankyou


Accepted Solutions
Solution
‎02-22-2016 09:52 AM
Super Contributor
Posts: 252

Re: How to get multiple linestyles in same sgplot graph ?

Hello, I agree with Sanjay's comments. Just wanted to also mention that the reason why you are getting the same linestyle for each treatment is because you are using this option "lineattrs = (pattern = 1)". If you remove that code from the options (and assuming you are creating listing or rtf output) than you will automatically get different linestyles for each treatment.

 

If you wanted to also specify the exact color and linestyle that each treatment should have than you can do this with the discrete attributes map statements. http://blogs.sas.com/content/graphicallyspeaking/2013/04/06/attributes-map-2/

 

Thanks.

View solution in original post


All Replies
SAS Super FREQ
Posts: 1,134

Re: How to get multiple linestyles in same sgplot graph ?

Starting with SAS 9.3, the default style for HTML destination is HTMLBLUE.  This uses a "Color" priority algorithm to cycle through the attributes such as color, line pattern and symbol.  If you have SAS 9.3, use some other style, like LISTING.

 

If you have SAS 9.4 and want to keep the HTMLBlue style , but change the attribute assignment, set ATTRPRIORITY=NONE on the ODS Graphics statement.  This will cycle through color and line patterns for each group.

 

See this article for more information on ATTRPRIORITY:  http://blogs.sas.com/content/graphicallyspeaking/2015/06/28/attributes-priority-for-the-inquiring-mi...

 

Occasional Contributor
Posts: 11

Re: How to get multiple linestyles in same sgplot graph ?

Thanks Sanjay. This helped me to learn something new.
Solution
‎02-22-2016 09:52 AM
Super Contributor
Posts: 252

Re: How to get multiple linestyles in same sgplot graph ?

Hello, I agree with Sanjay's comments. Just wanted to also mention that the reason why you are getting the same linestyle for each treatment is because you are using this option "lineattrs = (pattern = 1)". If you remove that code from the options (and assuming you are creating listing or rtf output) than you will automatically get different linestyles for each treatment.

 

If you wanted to also specify the exact color and linestyle that each treatment should have than you can do this with the discrete attributes map statements. http://blogs.sas.com/content/graphicallyspeaking/2013/04/06/attributes-map-2/

 

Thanks.

SAS Super FREQ
Posts: 1,134

Re: How to get multiple linestyles in same sgplot graph ?

Good catch.  I missed that part that LINEATTRS is specified.  It is also preferable to NOT use patterns by numbers as you may not get good results.  Please only use the named patterns defined in the software documentation.

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 413 views
  • 6 likes
  • 3 in conversation