BookmarkSubscribeRSS Feed
xizidememeda
Calcite | Level 5

Hi all!

 

I use the following code to plot a graph, however, I find that I cannot change the position of the legend. Is it because I changed the default size of the graph? I tried many times, but the legend position didn't change.

 

ods graphics on / width=12in;
ods graphics on / height=7in;

proc sgplot data=hor;
  keylegend / location=inside position=bottomleft;
  xaxis values=(1 2 3 4 5) label='portfolios';
  yaxis label='betas';
  y2axis label="gamma";
  highlow x=n high=MH low=ML;
  scatter x=n y=e / datalabel;
  scatter x=n y=r / datalabel y2axis;
run;

I appreciate it very much for your warm help!

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Give us data to plot.

Use one the SASHELP tables.

ballardw
Super User

@xizidememeda wrote:

Hi all!

 

I use the following code to plot a graph, however, I find that I cannot change the position of the legend. Is it because I changed the default size of the graph? I tried many times, but the legend position didn't change.

 

ods graphics on / width=12in;
ods graphics on / height=7in;

proc sgplot data=hor;
  keylegend / location=inside position=bottomleft;
  xaxis values=(1 2 3 4 5) label='portfolios';
  yaxis label='betas';
  y2axis label="gamma";
  highlow x=n high=MH low=ML;
  scatter x=n y=e / datalabel;
  scatter x=n y=r / datalabel y2axis;
run;

I appreciate it very much for your warm help!


Where does your legend appear?

 

If you specify a location that has lots of your plot values the legend is shifted to reduce collisions.

From the documentation:

   
If LOCATION=INSIDE is specified, the legend is automatically positioned near an edge of the plot area that has the least amount of collision with the data.

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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