如何在SAS 9.4的SGPanel同色系组内用填充图案区分VBAR
How to Add Fill Patterns to Same-Color Groups in SAS SGPanel VBAR Charts
Got it, let's tackle this! You want to differentiate groups that share the same color in your SGPanel bar chart using fill patterns—totally doable in SAS 9.4. Here's exactly how to adjust your code:
First, we'll add fill pattern definitions to your STYLEATTRS statement, matching the order of your existing color list. Then we'll tell the VBAR statement to apply these patterns by group.
Modified Code
proc sgpanel data=transp_5; panelby position / layout=columnlattice onepanel colheaderpos=bottom rows=2 novarname noborder; /* Add DATAPATTERNS to pair with your repeated color scheme */ styleattrs datacolours=(CXbe0a6e CXbe0a6e CXe17d00 CXe17d00 CXbcc121 CXbcc121 CX3caf7f CX3caf7f CX0077ad CX0077ad) datapatterns(SOLID X SOLID DOT SOLID DIAMOND SOLID CROSS SOLID STAR) /* Alternate patterns for same-color groups */ DATACONTRASTCOLORS=(nocolour); format position order.; format crop_type concatf.; /* Enable fill patterns for the group with FILLPATTERN=GROUP */ vbar crop_type / group=crop_type response=col1 stat=sum fillpattern=group; run;
Key Details:
DATAPATTERNSinSTYLEATTRS: This list maps directly to yourdatacolourslist. For each pair of same-color groups, we use a different pattern (e.g.,SOLIDandXfor the first two groups,SOLIDandDOTfor the next pair). SAS 9.4 supports patterns likeSOLID,X,DOT,DIAMOND,CROSS,STAR,HORIZONTAL,VERTICAL, etc.—feel free to swap these out for ones that work best for your chart.FILLPATTERN=GROUPinVBAR: This option tells SAS to apply the pattern defined inDATAPATTERNSto each group, ensuring same-color bars get distinct fill patterns.- Format Alignment: Make sure the order of your
concatf.format forcrop_typematches the order ofdatacoloursanddatapatterns—this ensures the right pattern/color is applied to each group.
内容的提问来源于stack exchange,提问作者Sandra L.
相关产品推荐
相关产品推荐

