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;
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;
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.
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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.