I have a scatter plot with some added lines but I don't want to show them in the legend - I must be referencing it wrong in the keylegend exclude options. Can anyone help?
proc sgplot data=work.data noborder;
scatter x=var1 y=var2 group=var3;
lineparm x=0 y=5 SLOPE=0;
lineparm x=70 y=0 SLOPE=5;
keylegend /
across=2
location=inside
position=bottomright
noborder
exclude = ("lineparm");
run;
Do you not need to name each plot for this to work?
proc sgplot data=work.data noborder noautolegend scatter x=var1 y=var2 group=var3 name="scatter"; lineparm x=0 y=5 slope=0 name="line1"; lineparm x=70 y=0 slope=5 name="line2"; keylegend "scatter" / across=2 location=inside position=bottomright noborder; run;
Note how I use don't mix in upper case - it makes reading code harder.
Do you not need to name each plot for this to work?
proc sgplot data=work.data noborder noautolegend scatter x=var1 y=var2 group=var3 name="scatter"; lineparm x=0 y=5 slope=0 name="line1"; lineparm x=70 y=0 slope=5 name="line2"; keylegend "scatter" / across=2 location=inside position=bottomright noborder; run;
Note how I use don't mix in upper case - it makes reading code harder.
You can reference your scatter plot in the Keylegend statement by using the name="scatter" in the scatter options and specify keylegend "scatter" to reference only the scatter plot in the legend.
Also, I think you are missing a / in your scatter statement before your group= option
Thanks - worked a charm (and there was a missing / - I removed various other options to make it simpler to paste it in and just got trigger happy with the delete key!)
So one other largely trivial thing to do on this plot that I can't figure out.... I have ten categories and in the legend they are listed by row then column, rather than going 1 to 5 on the left hand side and 6-10 on the right hand side. Can't find a way to edit this...
proc sgplot data=work.data noborder;
styleattrs dataconstrastcolors=("&colour10" "&colour9" "&colour8" "&colour7"
"&colour6" "&colour5" "&colour4" "&colour3" "&colour2" "&colour1");
scatter x=var1 y=var2 / name="scatter"
group=grouping_var
markerattrs=(size=4 symbol=CircleFilled);
lineparm x=0 y=1000 slope=0 / name="name1"
lineattrs=(colour="dark red" thickness=2);
lineparm x=1000 y=0 slope=99 / name="name2"
lineattrs=(colour="dark red" thickness=2);
xaxis max=25000 min=200 label="Title" labelattrs=(weight=bold);
yaxis reverse min=0 max=20000 label="Title" labelattrs=(weight=bold);
keylegend "scatter" /
title="Title"
titleattrs=(weight=bold)
across=2
location=inside
position=bottomright
noborder
opaque;
run;
@_123_ wrote:
So one other largely trivial thing to do on this plot that I can't figure out.... I have ten categories and in the legend they are listed by row then column, rather than going 1 to 5 on the left hand side and 6-10 on the right hand side. Can't find a way to edit this...
proc sgplot data=work.data noborder;
keylegend "scatter" /
title="Title"
titleattrs=(weight=bold)
across=2
location=inside
position=bottomright
noborder
opaque;
run;
You do not describe what you want your legend to look like but what do you think that highlighted option above does? It makes the legend have two columns. The DOWN option controls the number of rows.
Ideally I want two columns by five rows but the grouping is effectively by decile. When I put the across two in, I get an order like this:
1 2
3 4
5 6
7 8
9 10
It would be easier to read it like this:
1 6
2 7
3 8
4 9
5 10
It's not a deal breaker but it seems like something I should be able to fix (If I knew more about what I was doing!)
This post among other things shows how to control the order of the legend.
https://blogs.sas.com/content/graphicallyspeaking/2017/04/04/consistent-ordering-graph-components/
The following step creates the attribute map:
data attr(drop=n); retain ID 'a' Show 'AttrMap' ; input Value $ 1-9 n; LineStyle = cats('GraphData', n); MarkerStyle = linestyle; FillStyle = linestyle; TextStyleElement = linestyle; datalines; > 90 days 2 > 30 days 12 Current 3 ; |
It reads the instream data set that contains the values of the account status, and the number of the GraphDatan style element that is used for each. Assignment statements create all of the style variables that are available in an attribute map (even those that do not get used in this particular example). The variable Show='AttrMap' makes the legend appear in the order of the values in the attribute map data set. The following step shows a first pass at making the graph.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.