- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello, I have a problem with my legend - I cannot fit it into my graph, it always get clipped no matter what height/width/legendarea I use (it is important for me to keep this height and width as in the code). I'm using SAS 9.4 This is my code:
ods graphics / width=600 height=300 maxlegendarea=45 attrpriority=none;
proc sgplot DATA=vintagr noborder;
series x=seniority y=vintage3 /group=fin_period lineattrs=(pattern=solid) markers;
xaxis display=(nolabel) integer values=(2 to 36);
yaxis display=(nolabel noline) grid gridattrs=(thickness=2) integer values=(0 to 0.09 by 0.01);
keylegend / title='' across=9 noborder down=4;
run;
and my data is attached to file. If I try to use discretelegend statement with displayclipped=TRUE, to at least partially see the legend, I always get an error, as my SAS does not recognize displayclipped as an option of discretelegend.
Best regards
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The data shows you have 36 distinct groups. There are three ways to address this.
1. Increase MaxLegendArea. You already increased this to 45. You can go higher.
2. You can reduce the displayed LINELENGTH in the legend. LineLength=24 may work. For solid lines, lower value will work.
3. Another way is to separate your year and month into new columns. Now, you can color your lines by month (12) and use linepattern to show the year (3) using GROUPLC and GROUPLP options (see some examples in Graphically Speaking - Spaghetti Plot). Now, you need two legends, one for the color, which can be a short line (linelength=10), or just TYPE=COLOR, and one for patterns (3). Note, you still need the fin_priority group column.
series x=seniority y=vintage3 / group=fin_period grouplc=month grouplp=year lineattrs=(thickness=2);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It appears that you are attempting to show about 36 separate series (3 years of monthly values I would guess for you group variabl) on a single graph.
If you do not display any legend is the graph useful? That is so many lines I have a hard believing that graph is very readable.
VALUEATTRS in the Keylegend statement would allow you to specify size and font of the text used which may help considerably depending on which actual ODS destination and associated default font's are used. AUTOITEMSIZE would help adjust markers to match set font sizes. LINELENGTH in the Keylegend could also be used to shorten legend line segments to provide more room.
Note that a TEXT file is not data as we do not know what labels, formats or data types you assigned to variables. All of which can have some bearing on the appearance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
thank you, everything worked 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The data shows you have 36 distinct groups. There are three ways to address this.
1. Increase MaxLegendArea. You already increased this to 45. You can go higher.
2. You can reduce the displayed LINELENGTH in the legend. LineLength=24 may work. For solid lines, lower value will work.
3. Another way is to separate your year and month into new columns. Now, you can color your lines by month (12) and use linepattern to show the year (3) using GROUPLC and GROUPLP options (see some examples in Graphically Speaking - Spaghetti Plot). Now, you need two legends, one for the color, which can be a short line (linelength=10), or just TYPE=COLOR, and one for patterns (3). Note, you still need the fin_priority group column.
series x=seniority y=vintage3 / group=fin_period grouplc=month grouplp=year lineattrs=(thickness=2);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
A Spaghetti Plot with a Twist.
https://make-a-graph.com/2019/01/09/a-spaghetti-plot-with-a-twist/
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content