- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have the following data.
data have;
do groupname="Group 1","Group 2","Group 3";
do i=1 to 100;
x=2*substr(groupname,6)+rannor(1);
output;
end;
end;
run;
As I want to draw a histogram of three groups, I did the following.
proc sgplot;
histogram x/group=groupname transparency=0.3333;
density x/group=groupname type=kernel;
run;
Here's the outcome.
I tried to erase the "groupname" inside the bottom legend box, so used KEYLEGEND as follows.
proc sgplot;
histogram x/group=groupname transparency=0.3333;
density x/group=groupname type=kernel;
keylegend/title="";
run;
And it seems KEYLEGEND unties the items and the outcome repeats these groups twice.
How can I suppress the "groupname" here while avoiding this untying behavior? Thanks for your help.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You are getting two sets in the legend because the default is to provide a legend for each plot.
You can request which items to include in the legend by listing the names in the Keylegend statement. Which means that you use the options on the histogram and density statements to name their legend entries.
Example below should only show the legend for the histogram. Change 'Hist' to 'Dens' to show the density legend.
proc sgplot; histogram x/group=groupname transparency=0.3333 name='Hist'; density x/group=groupname type=kernel name='Dens'; keylegend 'Hist' / title="" ; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What version of SAS do you use?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You are getting two sets in the legend because the default is to provide a legend for each plot.
You can request which items to include in the legend by listing the names in the Keylegend statement. Which means that you use the options on the histogram and density statements to name their legend entries.
Example below should only show the legend for the histogram. Change 'Hist' to 'Dens' to show the density legend.
proc sgplot; histogram x/group=groupname transparency=0.3333 name='Hist'; density x/group=groupname type=kernel name='Dens'; keylegend 'Hist' / title="" ; run;