- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello, I am using globallegend to represent my legends but unfortunately, the legend is coming outside the plot area. Is there any way to get the legend inside the graph? here is the code:
proc template;
define statgraph globallegend;
begingraph;
entrytitle "Prediction Ellipses";
layout overlay;
scatterplot x=petallength y=petalwidth / group=species
name="sp";
ellipse x=petallength y=petalwidth / type=predicted alpha=0.2
name="p80" legendlabel="80%" outlineattrs=graphconfidence;
ellipse x=petallength y=petalwidth / type=predicted alpha=0.05
name="p95" legendlabel="95%" outlineattrs=graphconfidence2;
endlayout;
layout globalLegend / type=column title="Sample Global Legend";
discretelegend "sp" / title="Species:";
discretelegend "p80" "p95" / title="Predictions:";
endLayout;
endgraph;
end;
run;
proc sgrender data=sashelp.iris template=globallegend;
run;
Please help!!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
To do this, you need to use a LAYOUT GRIDDED inside of the LAYOUT OVERLAY:
proc template;
define statgraph globallegend;
begingraph;
entrytitle "Prediction Ellipses";
layout overlay;
scatterplot x=petallength y=petalwidth / group=species
name="sp";
ellipse x=petallength y=petalwidth / type=predicted alpha=0.2
name="p80" legendlabel="80%" outlineattrs=graphconfidence;
ellipse x=petallength y=petalwidth / type=predicted alpha=0.05
name="p95" legendlabel="95%" outlineattrs=graphconfidence2;
layout gridded / border=true autoalign=(topleft topright bottomleft bottomright);
entry halign=left "Sample Global Legend" / textattrs=GraphLabelText;
entry halign=left "Species:" / textattrs=GraphLabelText;
discretelegend "sp" / border=false halign=left;
entry halign=left "Predictions:" / textattrs=GraphLabelText;
discretelegend "p80" "p95" / border=false halign=left;
endlayout;
endlayout;
endgraph;
end;
run;
proc sgrender data=sashelp.iris template=globallegend;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatgraph/p0nebkqa1obtgxn13ska62up7wwh.h...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
LAYOUT GLOBALLEGEND is outside of all other layouts by design. You can put both of your DISCRETELEGENDS inside of the LAYOUT OVERLAY and use the AUTOALIGN feature to have the legends position themselves in a way to prevent data collision (if possible). Would that work for you?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I tried this as well, but it didn't work. Any other suggestion
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Did your layout overlay look like this?
layout overlay;
scatterplot x=petallength y=petalwidth / group=speciesname="sp";
ellipse x=petallength y=petalwidth / type=predicted alpha=0.2
name="p80" legendlabel="80%" outlineattrs=graphconfidence;
ellipse x=petallength y=petalwidth / type=predicted alpha=0.05
name="p95" legendlabel="95%" outlineattrs=graphconfidence2;
discretelegend "sp" / title="Species:" location=inside autoalign=(topleft topright bottomleft bottomright);
discretelegend "p80" "p95" / title="Predictions:" location=inside autoalign=(topleft topright bottomleft bottomright);
endlayout;
The LAYOUT GLOBALLEGEND block should be removed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I get the picture below with the code I gave you. Is there a particular way you want the legends arranged?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Like this:
Species
symbol Setosa
symbol Versicolor
symbol Viginica
Predictions
symbol 80%
symbol 95%
Along with the vertical alignment, i want them to be placed on the right side of the plot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
To do this, you need to use a LAYOUT GRIDDED inside of the LAYOUT OVERLAY:
proc template;
define statgraph globallegend;
begingraph;
entrytitle "Prediction Ellipses";
layout overlay;
scatterplot x=petallength y=petalwidth / group=species
name="sp";
ellipse x=petallength y=petalwidth / type=predicted alpha=0.2
name="p80" legendlabel="80%" outlineattrs=graphconfidence;
ellipse x=petallength y=petalwidth / type=predicted alpha=0.05
name="p95" legendlabel="95%" outlineattrs=graphconfidence2;
layout gridded / border=true autoalign=(topleft topright bottomleft bottomright);
entry halign=left "Sample Global Legend" / textattrs=GraphLabelText;
entry halign=left "Species:" / textattrs=GraphLabelText;
discretelegend "sp" / border=false halign=left;
entry halign=left "Predictions:" / textattrs=GraphLabelText;
discretelegend "p80" "p95" / border=false halign=left;
endlayout;
endlayout;
endgraph;
end;
run;
proc sgrender data=sashelp.iris template=globallegend;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Just a quick question what option do I need to use if I want a space between viriginica and predications. like i want to show that there are two different titles. A space will work i think. Any leads?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Before the "Predictions:" entry, just add a " " entry:
entry halign=left " ";
entry halign=left "Predictions:" / textattrs=GraphLabelText;
You can do the same thing before "Species:" if you want a gap between the legend and the global title.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
"Didn't work" is awful vague.
Are there errors in the log?: Post the code and log in a code box opened with the "</>" to maintain formatting of error messages.
No output? Post any log in a code box.
Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "</>" icon or attached as text to show exactly what you have and that we can test code against.
In other words, Show the code you actually used and best from the log as the messages SAS provides often will indicate what is needed.