Data visualization with SAS programming

How to draw in legend as scatter as series

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 146
Accepted Solution

How to draw in legend as scatter as series

Hi all,

 

Could you please advise in the following case. I'm using the following code but can not receive correct legend where as scatter as series are listed:

                                                      
proc sgplot data=F1 ;

   styleattrs datacontrastcolors=(black)
               datasymbols=(trianglefilled circlefilled squarefilled diamondfilled triangle circle square diamond)
               datalinepatterns=(solid); 

   scatter x=PCTPT y=mean / group=TRT01A_PL grouporder=data
                            yerrorlower=lower                                                                                            
                            yerrorupper=upper
                            name = "customlegend" ;                                                                               
   series x=PCTPT y=mean / ;

   xaxis type=discrete;
   yaxis type=linear; 

   keylegend "customlegend" / location=inside position=topright;
   format PCTPT $PCTPTF.;
 
run;  

Here it is the result:

5.jpg

Here it is the needed view:

4.jpg

 

How can it be resolved? Thank you!

 


Accepted Solutions
Solution
‎11-03-2017 01:57 PM
SAS Super FREQ
Posts: 1,184

Re: How to draw in legend as scatter as series

Posted in reply to DmytroYermak

You need to turn on the MARKERS in the series plot.  You can then keep only the error bars in the scatter, or leave that as is.  Include only the series plot in the legend.

View solution in original post


All Replies
SAS Super FREQ
Posts: 1,184

Re: How to draw in legend as scatter as series

Posted in reply to DmytroYermak

You have named your scatter plot NAME="CustomLegend".  It is better to name your plot statements by what they do, like "Scatter" and "Series".  Then, you can include the appropriate names on the KEYLEGEND statement as :  keylegend "Scatter" "Series".  This will get legend entries from both statements.  If you want combined symbols as you show then put just the "Series" in the keylegend.

Frequent Contributor
Posts: 146

Re: How to draw in legend as scatter as series

Posted in reply to Sanjay_SAS

Thank you for your kind help.

 

I have modified the code. Here it is:

 

                                                        
proc sgplot data=F1 noautolegend;

   styleattrs datacontrastcolors=(black)
               datasymbols=(trianglefilled circlefilled squarefilled diamondfilled triangle circle square diamond)
               datalinepatterns=(solid solid solid  solid  solid solid solid solid ); 

   scatter x=PCTPT y=mean / group=TRT01A_PL 
                            grouporder=data
                            yerrorlower=lower                                                                                            
                            yerrorupper=upper
							name = "Scatter" ;                                                                              
   series x=PCTPT y=mean /  group=TRT01A_PL name = "Series";;

   xaxis type = discrete;
   yaxis type = linear;

   keylegend "Series"  / location=inside position=topright across=1 noborder;
   format PCTPT $PCTPTF.;
 
run; 

But when I used just 'Series' I received this output:

 

2.jpg

 

When I put "Scatter" "Series" I received the following output (unfortunately not combined ( ):

1.jpg 

Solution
‎11-03-2017 01:57 PM
SAS Super FREQ
Posts: 1,184

Re: How to draw in legend as scatter as series

Posted in reply to DmytroYermak

You need to turn on the MARKERS in the series plot.  You can then keep only the error bars in the scatter, or leave that as is.  Include only the series plot in the legend.

Frequent Contributor
Posts: 146

Re: How to draw in legend as scatter as series

Posted in reply to Sanjay_SAS

Bingo!! It has worked! Thank you!

Frequent Contributor
Posts: 146

Re: How to draw in legend as scatter as series

Posted in reply to DmytroYermak

Final code (if someone is interested):

 

proc sgplot data=F1 noautolegend;

   styleattrs datacontrastcolors=(black)
               datasymbols=(trianglefilled circlefilled squarefilled diamondfilled triangle circle square diamond)
               datalinepatterns=(solid); 

   scatter x=PCTPT y=mean / group=TRT01A
							grouporder=data
                            yerrorlower=lower                                                                                            
                            yerrorupper=upper
                            name = "Scatter" ;                                                                               
   series x=PCTPT y=mean /  markers group=TRT01A name = "Series";

   xaxis type = discrete;
   yaxis type = log;

   keylegend "Series"  / location=outside position=topright across=1 noborder;
   format PCTPT $PCTPTF.;
 
run;  
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 117 views
  • 2 likes
  • 2 in conversation