BookmarkSubscribeRSS Feed
moreka
Obsidian | Level 7

Is there anyway to alter the style of error bars by group in regards to line style or thickness?

I'm working on a graph where the error bars overlap, so I want them to appear distinct on the graph.

I've attempted with SGPLOT and SGDESIGN, but have only been able to differentiate the groups by color. 

 

I do not want to stagger the bars using the cluster option.

 

These are examples of the code I'm working with.


proc template;
define statgraph sgdesign;
dynamic __XCLAS __PREDICTED __UCLM __LCLM __GROUP2;
begingraph / dataskin=none attrpriority=Auto DataColors=(CX000000 CX848284) DataContrastColors=(CX000000 CXA4A5A4) DataLinePatterns=(4 1) DataSymbols=(circlefilled trianglefilled);
   layout lattice / rowdatarange=data columndatarange=data rowgutter=10 columngutter=10;
      scatterplot x=__XCLAS y=__PREDICTED / group=__GROUP2 yerrorupper=__UCLM yerrorlower=__LCLM name='scatter' groupdisplay=Overlay errorbarattrs=(thickness=1);
   endlayout;
endgraph;
end;
run;

proc sgrender data=B.EFFECTPLOTRAWDATA1 template=sgdesign;
dynamic __XCLAS="'_XCLAS'n" __PREDICTED="'_PREDICTED'n" __UCLM="'_UCLM'n" __LCLM="'_LCLM'n" __GROUP2="'_GROUP'n" ;
run;

proc sgplot data=b.effectPlotRawData1;
scatter x = _XCLAS y = _PREDICTED / yerrorupper=_UCLM yerrorlower=_LCLM group=_INDEX name='scatter' ERRORBARATTRS=(THICKNESS = 1);
styleattrs datacontrastcolors=(black darkgray) datalinepatterns=(ShortDash LongDash);
;run;
7 REPLIES 7
DanH_sas
SAS Super FREQ

Instead of varying the error bar attributes, your best option might be to set GROUPDISPLAY=CLUSTER on the SCATTER plot. Give that a try and see what you think.

moreka
Obsidian | Level 7

I do not want to stagger the bars using the cluster option.

 

But thank you for the suggestion.

DanH_sas
SAS Super FREQ

If you are using ODS HTML, the default style is HTMLBlue, which is set up as an ATTRPRIORITY=COLOR style. If you override this setting, you will get different line patterns for each group. Try adding this setting before you run the graph code:

 

odd graphics / attrpriority=none;

moreka
Obsidian | Level 7

If I am graphing a series, this will let me change the pattern for the lines, but unless I'm using it incorrectly, this does not allow me to change the line pattern on the error bars specifically.

Rick_SAS
SAS Super FREQ

Can you provide data? Or at least a picture of what you want?

moreka
Obsidian | Level 7
data graphdata; 
input _PREDICTED _XCLAS _GROUP2 _UCLM _LCLM;
datalines;
 0.50  2  1  0.55  0.44
 0.46  3  1  0.52  0.41
 0.43  4  1  0.50  0.36
 0.28  2  2  0.41  0.15
 0.36  3  2  0.51  0.22
 0.46  4  2  0.55  0.38
run;

I think I will just have to split the groups into two separate scatterplots and apply different styles to each.

Athenkosi
Obsidian | Level 7

Hello,

Errorbar attributes: For grouped data, the linestyle and linethickness attributes come from the GraphError style element and the ContrastColor attribute comes from the GraphData1-GraphDataN style elements. This means the linestyle and linethickness attributes are fixed and the only attribute that can differ between groups is the ContrastColor. 

 

A solution is to draw the errorbars by overlaying a highlowplot over the scatterplot, see solution below.

 

data graphdata; 
input _PREDICTED _XCLAS _GROUP2 _UCLM _LCLM;
datalines;
 0.50  2  1  0.55  0.44
 0.46  3  1  0.52  0.41
 0.43  4  1  0.50  0.36
 0.28  2  2  0.41  0.15
 0.36  3  2  0.51  0.22
 0.46  4  2  0.55  0.38
 ;
run;

ods graphics / attrpriority=none;

proc sgplot data=graphdata noautolegend;
	styleattrs DataContrastColors=(CX000000 CXA4A5A4) 
			   DataLinePatterns=(1 2) 
			   DataSymbols=(circlefilled trianglefilled);
			   
	scatter x=_XCLAS y=_PREDICTED / 
		group=_GROUP2;
		
	highlow x=_XCLAS low=_LCLM high=_UCLM /
		group=_GROUP2
		highcap=serif
		lowcap=serif;
run;
	

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2487 views
  • 8 likes
  • 4 in conversation