The SAS Output Delivery System and reporting techniques

Changing legend location in AgreePlot

Accepted Solution Solved
Reply
Contributor
Posts: 38
Accepted Solution

Changing legend location in AgreePlot

[ Edited ]

Hi there,

 

I'm a SAS EG 7.1 HF1 (7.100.0.2002) (64-bit) user.

I'm trying to change the legend location of an Agree Plot generated with PROC FREQ from its default location (bottomright) to topleft (to avoid overlapping with the plot lines). Here is the code that I've used to produce the plot:

 

ods graphics on;
proc freq data=sashelp.baseball;
	table League*Division / agree nocol norow; 
	test kappa;
run;
ods graphics off;

Then I have used an ODS TRACE ON statement to look for the proper template that I have to modify which is Base.Freq.Graphics.AgreePlot. I have obtained the full default template with:

 

proc template;
	source Base.Freq.Graphics.AgreePlot;
run;

The full template (where I have highlighted in red the places where I want something changed) is:

 

define statgraph Base.Freq.Graphics.AgreePlot;
   notes "Agreement Plot";
   dynamic _ROWVARNAME _ROWVARLABEL _SROWVARLABEL _COLVARNAME _COLVARLABEL _SCOLVARLABEL _XTICKS _YTICKS _XTICKLABELS _YTICKLABELS
      _PARTIAL _LEGEND _SCALE _ALIGN _STATS _BN _KAPPA _PWTK _WTKAPPA _N _byline_ _bytitle_ _byfootnote_;
   begingraph / includeMissingDiscrete=true;
      entrytitle "Agreement of " _ROWVARNAME " and " _COLVARNAME;
      layout overlay / aspectratio=1 yaxisopts=(offsetmax=0 offsetmin=0 label=_COLVARLABEL shortlabel=_SCOLVARLABEL linearopts=(
         tickvaluelist=_YTICKS tickdisplaylist=_YTICKLABELS)) y2axisopts=(offsetmax=0 offsetmin=0 label='Cumulative Frequency'
         display=_SCALE linearopts=(thresholdmin=0 thresholdmax=0)) xaxisopts=(offsetmax=0 offsetmin=0 label=_ROWVARLABEL
         shortlabel=_SROWVARLABEL linearopts=(tickvaluelist=_XTICKS tickdisplaylist=_XTICKLABELS tickvaluefitpolicy=staggerrotate));
         if (_PARTIAL)
            bandplot x=_X limitlower=_BL limitupper=_BU / type=step datatransparency=.7 name='b' legendlabel='Partial Agreement'
               rolename=(tip1=_PARTIALFREQ tip2=_PARTIALPERCENT) tiplabel=(tip1="Frequency" tip2="Percent") tip=(tip1 tip2);
            if (_LEGEND)
               discretelegend 'a' 'b' / across=1 autoalign=(bottomright) location=inside;
            endif;
         else
            if (_LEGEND)
               discretelegend 'a' / autoalign=(bottomright) location=inside;
            endif;
         endif;
         bandplot x=_X limitlower=_AL limitupper=_AU / type=step yaxis=y2 name='a' legendlabel='Exact Agreement' rolename=(tip1=
            _ROW tip2=_COLUMN tip3=_FREQ tip4=_PERCENT) tip=(tip1 tip2 tip3 tip4);
         seriesplot x=_X y=_YL / rolename=(tip1=_ROW tip2=_ROWFREQ tip3=_ROWPERCENT) tip=(tip1 tip2 tip3);
         seriesplot x=_X y=_YU / rolename=(tip1=_COLUMN tip2=_COLUMNFREQ tip3=_COLUMNPERCENT) tip=(tip1 tip2 tip3);
         drawline x1=0 y1=0 x2=100 y2=100 / x1space=datapercent y1space=datapercent x2space=datapercent y2space=datapercent
            transparency=.8 lineattrs=(thickness=1);
         if (_STATS)
            layout gridded / border=true columns=2 BackgroundColor=GraphWalls:Color Opaque=true shrinkfonts=true autoalign=_ALIGN;
               entry halign=left "B_N";
               entry halign=right eval (PUT(_BN, 6.4));
               entry halign=left "Kappa" / pad=(right=5);
               entry halign=right eval (PUT(_KAPPA, 6.4));
               if (_PWTK)
                  entry halign=left "Wt Kappa" / pad=(right=5);
                  entry halign=right eval (PUT(_WTKAPPA, 6.4));
               endif;
               entry halign=left "N";
               entry halign=right eval (PUT(_N, BEST7.));
            endlayout;
         endif;
      endlayout;
      if (_BYTITLE_)
         entrytitle _BYLINE_ / textattrs=GRAPHVALUETEXT;
      else
         if (_BYFOOTNOTE_)
            entryfootnote halign=left _BYLINE_;
         endif;
      endif;
   endgraph;
end;

I have tried to copy it to a PROC TEMPLATE and change directly the "bottomright" by "topleft" before executing it, but it's not working. What is the easiest way to achieve what I'm trying? Is there a way to replace only the part that I'm interested on? Do you have to modify the default template editing it or can you create a new one with these new specifications and apply it to the PROC FREQ afterwards?

 

Thanks in advance for your help!! Smiley Happy


Accepted Solutions
Solution
‎05-31-2017 11:22 AM
Contributor
Posts: 38

Re: Changing legend location in AgreePlot


All Replies
Contributor
Posts: 38

Re: Changing legend location in AgreePlot

[ Edited ]

UPDATE: It was just a silly error that was preventing my code from running properly and now it's working fine. Now I'm wondering if there is a simpler way for just changing the value of a single template parameter than "PROC TEMPLATE" the full template with the wanted changes.

 

Thanks again for your help!! Smiley Happy

Solution
‎05-31-2017 11:22 AM
Contributor
Posts: 38

Re: Changing legend location in AgreePlot

I have finally found a place where I have found the solution to all my doubts:

https://support.sas.com/documentation/cdl/en/statug/63962/HTML/default/viewer.htm#statug_templt_sect...

 

Smiley Happy

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 144 views
  • 0 likes
  • 1 in conversation