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

Hello Everyone,


I was wondering if there was a way to rename the character names of variables directly in the legend. I have a scatterplot that looks great but the legend says "Indian" and "Arctic" with the corresponding symbols. Is there any way I can make the legend say "Indian Ocean" and "Arctic Ocean" directly on the graph?


Thanks for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
Tracey_D
Calcite | Level 5

I would use legendlabel='Indian Ocean' as an option under seriesplot of your graph and the same for Arctic Ocean.

View solution in original post

2 REPLIES 2
Tracey_D
Calcite | Level 5

I would use legendlabel='Indian Ocean' as an option under seriesplot of your graph and the same for Arctic Ocean.

GraphGuy
Meteorite | Level 14

As a "best practice", I would recommend using a data-driven solution, rather than hard-coding the text.  If you hard-code text in the legend, then one day if/when the data changes, then the hard-coded legend will be wrong (which could go un-noticed and compromise the data-integrity of the graph).

You don't mention which proc you're using, so here's an example using traditional gplot...

Here's a plot with 'M' and 'F' in the legend:

legend1 label=none position=(bottom center);

proc gplot data=sashelp.class;

plot height*weight=sex / legend=legend1;

run;

Now, instead of 'M' and 'F', let's say we want 'Male' and 'Female' to show up in the legend.  You could either create a user-defined format that makes 'M' and 'F' show up as 'Male' and 'Female' ... or you could add an extra variable to the data, like so ...

data mod_class; set sashelp.class;
length mod_sex $10;
if sex='M' then mod_sex='Male';
else if sex='F' then mod_sex='Female';
else mod_sex=sex;
run;

legend1 label=none position=(bottom center);
proc gplot data=mod_class;
plot height*weight=mod_sex / legend=legend1;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1019 views
  • 0 likes
  • 3 in conversation