BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jenningsa
Fluorite | Level 6

Hello,

I am wondering if it is possible to add multiple symbols to one legend line. 

For example, the Flowering Status legend:

   I would like to have on the same line for 'Flowering', one green, one black, and one goldenrod coloured filled circle (so three circles of different colours) and the same for "Not Flowering' but for open circles.

I have attached the code I used to generate the figure below and what the current figure looks like. 

Thank you for any help resolving this conundrum.

 

ods graphics on / noborder attrpriority=none imagemap=off antialias imagename="allo" reset=index;
proc sgplot data=test noautolegend noborder;

	styleattrs datacontrastcolors=(goldenrod green black)
			   datacolors=(goldenrod green black)
			   datalinepatterns=(solid)
			   datasymbols=(circlefilled circle);

reg x=logtotclonemass y=logrhiz / group=fate2  nomarkers lineattrs=(thickness=3);
series x=logtotclonemass y=logrhiz / group=fate2 grouporder=reversedata groupms=flowering lineattrs=(thickness=0) markers markerattrs=(size=7) ;

xaxis label="Log aboveground biomass (g)" labelattrs=(color=black size=14) valueattrs=(color=black size=13) ;
yaxis label="Log caudex biomass (g)" labelattrs=(color=black size=14) valueattrs=(color=black size=13) ;

legenditem type=line name="V" / label="Vegetative" lineattrs=(thickness=2 color=green pattern=solid);
legenditem type=line name="R" / label="Reproductive" lineattrs=(thickness=2 color=goldenrod pattern=solid);
legenditem type=line name="D" / label="Dead" lineattrs=(thickness=2 color=black pattern=solid);

legenditem type=marker name="F" / label="Flowering" markerattrs=(symbol=circlefilled color=DAGR);
legenditem type=marker name="NF" / label="Not Flowering" markerattrs=(symbol=circle color=DAGR);

keylegend "V" "R" "D" / location=outside position=bottom noborder down=1 outerpad=(top=6mm) type=line
	title="Fate of Main Stem" titleattrs=(color=black size=13) valueattrs=(color=black size=13);

keylegend "F" "NF" / title="Flowering Status" location=inside position=topleft noborder down=3 /*type=markersymbol*/
	titleattrs=(color=black size=10) valueattrs=(color=black size=10) autoitemsize;

run;
ods graphics off;
caudex allocation X FATE X FLOWERING.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

OK. It is really uneasy . You need adapt it to your code.

 

data class;
set sashelp.class;
run;

proc sql ;
create table point as
select min(weight) as x1,max(height) as y1 from class;
quit;
data text;
 set point;
 text_x1=x1-2;text_y1=y1;text='Flowering Status';output;
 text_x1=x1+4;text_y1=y1-1;text='Flowering ';output;
 text_x1=x1+4;text_y1=y1-2;text='Not Flowering';output;
 keep text_x1 text_y1 text;
run;
data point1;
 set point;
y1=y1-1; 
do i=1 to 3;
output;
end;
run;
data point2;
 set point(rename=(x1=x2 y1=y2));
y2=y2-2; 
do j=1 to 3;
output;
end;
run;

data have;
 merge class point1 point2 text;
 if age>14 then do; _w=weight;_h=height;end;
run;



proc sgplot data=have noautolegend;
styleattrs datacontrastcolors=(goldenrod green black)  datacolors=(goldenrod green black) ;
reg x=weight y=height / group=sex  ;

/*scatter x=text_x1 y=text_y1 /markerchar=text;*/
text x=text_x1 y=text_y1 text=text /contributeoffsets=none strip position=right textattrs=(size=10);

scatter x=_w y=_h/group=sex markerattrs=(symbol=circlefilled);
scatter x=x1 y=y1/group=i groupdisplay=cluster CLUSTERWIDTH=0.2  markerattrs=(size=8 symbol=circlefilled);
scatter x=x2 y=y2/group=j groupdisplay=cluster CLUSTERWIDTH=0.2  markerattrs=(size=8);

legenditem type=line  name='x'/ label="Vegetative" lineattrs=(color=green pattern=solid) markerattrs=(color=green symbol=circlefilled);
legenditem type=line  name='y'/ label="Reproductive" lineattrs=(color=goldenrod  pattern=solid) markerattrs=(color=goldenrod  symbol=circlefilled);
legenditem type=line  name='z'/ label="Dead" lineattrs=(color=black  pattern=solid) markerattrs=(color=black  symbol=circlefilled);

keylegend 'x' 'y' 'z' /location=outside position=bottom noborder down=1 outerpad=(top=6mm) type=line
 title="Fate of Main Stem" titleattrs=(color=black size=13) valueattrs=(color=black size=13); ;

xaxis display=(nolabel) offsetmin=0.05;
yaxis display=(nolabel) offsetmin=0.05 offsetmax=0.05;
run;

Ksharp_0-1637149742849.png

 

View solution in original post

4 REPLIES 4
Ksharp
Super User

You want this ?

 

data class;
set sashelp.class;
if age>14 then do; _w=weight;_h=height;end;
run;


proc sgplot data=class noautolegend;
styleattrs datacontrastcolors=(goldenrod green black)  datacolors=(goldenrod green black) ;
reg x=weight y=height / group=sex  ;
scatter x=_w y=_h/group=sex markerattrs=(symbol=circlefilled);

legenditem type=MARKERLINE name='x'/ label="Vegetative" lineattrs=(color=green pattern=solid) markerattrs=(color=green symbol=circlefilled);
legenditem type=MARKERLINE name='y'/ label="Reproductive" lineattrs=(color=goldenrod  pattern=solid) markerattrs=(color=goldenrod  symbol=circlefilled);
legenditem type=MARKERLINE name='z'/ label="Dead" lineattrs=(color=black  pattern=solid) markerattrs=(color=black  symbol=circlefilled);

legenditem type=MARKERLINE name='x1'/ label="Vegetative" lineattrs=(color=green pattern=solid) markerattrs=(color=green );
legenditem type=MARKERLINE name='y1'/ label="Reproductive" lineattrs=(color=goldenrod  pattern=solid) markerattrs=(color=goldenrod  );
legenditem type=MARKERLINE name='z1'/ label="Dead" lineattrs=(color=black  pattern=solid) markerattrs=(color=black );

keylegend 'x' 'y' 'z' / title="Flowering" across=1 location=inside;
keylegend 'x1' 'y1' 'z1' / title="No Flowering" across=1 location=inside position=w;

run;
jenningsa
Fluorite | Level 6

Hi,

 

That is not quite what I am looking for. 

Here's a picture of what I would like the legend to look like 

Screenshot 2021-11-16 112737.png

 

Ksharp
Super User

OK. It is really uneasy . You need adapt it to your code.

 

data class;
set sashelp.class;
run;

proc sql ;
create table point as
select min(weight) as x1,max(height) as y1 from class;
quit;
data text;
 set point;
 text_x1=x1-2;text_y1=y1;text='Flowering Status';output;
 text_x1=x1+4;text_y1=y1-1;text='Flowering ';output;
 text_x1=x1+4;text_y1=y1-2;text='Not Flowering';output;
 keep text_x1 text_y1 text;
run;
data point1;
 set point;
y1=y1-1; 
do i=1 to 3;
output;
end;
run;
data point2;
 set point(rename=(x1=x2 y1=y2));
y2=y2-2; 
do j=1 to 3;
output;
end;
run;

data have;
 merge class point1 point2 text;
 if age>14 then do; _w=weight;_h=height;end;
run;



proc sgplot data=have noautolegend;
styleattrs datacontrastcolors=(goldenrod green black)  datacolors=(goldenrod green black) ;
reg x=weight y=height / group=sex  ;

/*scatter x=text_x1 y=text_y1 /markerchar=text;*/
text x=text_x1 y=text_y1 text=text /contributeoffsets=none strip position=right textattrs=(size=10);

scatter x=_w y=_h/group=sex markerattrs=(symbol=circlefilled);
scatter x=x1 y=y1/group=i groupdisplay=cluster CLUSTERWIDTH=0.2  markerattrs=(size=8 symbol=circlefilled);
scatter x=x2 y=y2/group=j groupdisplay=cluster CLUSTERWIDTH=0.2  markerattrs=(size=8);

legenditem type=line  name='x'/ label="Vegetative" lineattrs=(color=green pattern=solid) markerattrs=(color=green symbol=circlefilled);
legenditem type=line  name='y'/ label="Reproductive" lineattrs=(color=goldenrod  pattern=solid) markerattrs=(color=goldenrod  symbol=circlefilled);
legenditem type=line  name='z'/ label="Dead" lineattrs=(color=black  pattern=solid) markerattrs=(color=black  symbol=circlefilled);

keylegend 'x' 'y' 'z' /location=outside position=bottom noborder down=1 outerpad=(top=6mm) type=line
 title="Fate of Main Stem" titleattrs=(color=black size=13) valueattrs=(color=black size=13); ;

xaxis display=(nolabel) offsetmin=0.05;
yaxis display=(nolabel) offsetmin=0.05 offsetmax=0.05;
run;

Ksharp_0-1637149742849.png

 

jenningsa
Fluorite | Level 6

Thank you so much, after adapting it to my code and data it worked perfectly. Mahalo. 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 948 views
  • 0 likes
  • 2 in conversation