I am trying to make a panel plot in which each panel has a set of gray lines that represent individual units and a dark blue line that is the average of those units.The problem with my chart is that I cannot seem to place the blue line atop the other gray lines. As you can see, the blue line is behind the gray ones.
I am currently using an attribute map to style the blue line. The gray lines get their color from within the SGPANEL procedure as such:
data attrmap;
length ID $ 10 Value $ 8 linecolor $ 15 markercolor $ 15 linethickness 3 linepattern $ 10 markersymbol $ 20;
infile datalines delimiter='|';
input id value linecolor markercolor linethickness linepattern markersymbol ;
cards;
SchoolID|Mean|CX004c6d |CX004c6d|4|Solid|SquareFilled
;
proc sgpanel data= have noautolegend dattrmap=attrmap;
panelby class_new1 / spacing=5 novarname rows=3 columns=2 sort=data ;
styleattrs datacolors=(gray) datacontrastcolors=(gray) datasymbols=(circle) datalinepatterns=(shortdash) ;
series x=DOU_var y=DOU_score / group=SchoolID attrid=SchoolID name="line";
scatter x=dou_var y=dou_score/ group=SchoolID attrid=SchoolID jitter transparency=.2;
rowaxis grid min=0 max=1;
Are there ways to put the blue line atop the other gray ones so that it stands out?
If I understand what you are saying, that is because your "blue line" is drawn before the others. If the blue line come from a different value of the Group variable then it likely means that the value for that line is seen by the proc before the others and drawn first.
If this were my project I would have separate plot statement that just created the blue line, possibly a different group variable that is only defined for the blue line, that is after the first series plot. Make the Blue not transparent for greatest contrast. Something like
proc sgpanel data= have noautolegend dattrmap=attrmap; panelby class_new1 / spacing=5 novarname rows=3 columns=2 sort=data ; styleattrs datacolors=(gray) datacontrastcolors=(gray) datasymbols=(circle) datalinepatterns=(shortdash) ; series x=DOU_var y=DOU_score / group=SchoolID attrid=SchoolID name="line"; series x=DOU_var y=DOU_score / group=OtherSchoolID attrid=otherSchoolID ; scatter x=dou_var y=dou_score/ group=SchoolID attrid=SchoolID jitter transparency=.2; rowaxis grid min=0 max=1;
Which would require either adding another attrid to the Dattrmap OR you could specify the color directly with a lineattrs statement. If the OtherSchoolID variable is only on some records those are tho only wants shown.
Need to add a Keylegend to only show the "Line" items to prevent two "blue" line entries in the legend with this approach.
Another may be to sort the data so the "blue Line" group appears last in the data order but can't tell how difficult that may be without example data.
If I understand what you are saying, that is because your "blue line" is drawn before the others. If the blue line come from a different value of the Group variable then it likely means that the value for that line is seen by the proc before the others and drawn first.
If this were my project I would have separate plot statement that just created the blue line, possibly a different group variable that is only defined for the blue line, that is after the first series plot. Make the Blue not transparent for greatest contrast. Something like
proc sgpanel data= have noautolegend dattrmap=attrmap; panelby class_new1 / spacing=5 novarname rows=3 columns=2 sort=data ; styleattrs datacolors=(gray) datacontrastcolors=(gray) datasymbols=(circle) datalinepatterns=(shortdash) ; series x=DOU_var y=DOU_score / group=SchoolID attrid=SchoolID name="line"; series x=DOU_var y=DOU_score / group=OtherSchoolID attrid=otherSchoolID ; scatter x=dou_var y=dou_score/ group=SchoolID attrid=SchoolID jitter transparency=.2; rowaxis grid min=0 max=1;
Which would require either adding another attrid to the Dattrmap OR you could specify the color directly with a lineattrs statement. If the OtherSchoolID variable is only on some records those are tho only wants shown.
Need to add a Keylegend to only show the "Line" items to prevent two "blue" line entries in the legend with this approach.
Another may be to sort the data so the "blue Line" group appears last in the data order but can't tell how difficult that may be without example data.
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!
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.
Ready to level-up your skills? Choose your own adventure.