Hallo,
I used "proc sgplot" to create a bar chart.
I want to complete it with a legend, but I can't find a solution.
I found examples for "proc gplot", but I don't want to change all of my work.
here is my code:
proc sgplot data=Grafik; | |
Title "Stabdiagramm der Variable: Geschlecht"; | |
yaxis label="Absolute Häufigkeit"; | |
xaxis label="Geschlecht der Studierenden"; | |
vbar Geschlecht / barwidth=0.3; | |
run; |
Thank you for the support!
Daniel
The best alternative for putting them outside the graph is to use multiple FOOTNOTE statements. To make the graph itself bigger, you can use the WIDTH and HEIGHT options on the ODS GRAPHICS statement.
Thanks!
Dan
Hi.
Yes you can, but I think you may need to use PROC TEMPLATE/PROC SGRENDER
Here is a code example:
proc template;
define statgraph sgdesign;
begingraph;
entrytitle halign=center 'Type in your title...';
entryfootnote halign=left 'Type in your footnote...';
layout lattice / rowdatarange=data columndatarange=data rowgutter=10 columngutter=10;
layout overlay;
barchart x=SEX y=HEIGHT / name='bar' clusterwidth=1.0 fillattrs=(color=CXA4A5A4 );
discretelegend 'bar' / opaque=false border=true halign=left valign=bottom displayclipped=true across=1 order=rowmajor location=inside;
endlayout;
endlayout;
endgraph;
end;
run;
1111
proc sgrender data=SASHELP.CLASS template=sgdesign;
run;
SGPLOT will automatically create a legend when needed. Since you don't have any group variable or other features, there is no need for a legend. However, if you want, you can add a KEYLEGEND statement of your own, with a reference to a name of the plot. Please see product documentation.
Thank you for the support!
But I have the problem, that I used numbers for the obsvervation values of a nominal variable.
Now I want to add a "description", where I can explain, what each number means.
I look forward to the answer,
Daniel
I'm not clear how you represent the "observation values" in your graph, but I have a couple of thoughts:
1. If each bar represents an observation, you can create a separate column containing the descriptions that lines up with your "Geschlecht" variable values and assign it to the GROUP option on the VBAR statement. The legend will automatically show the descriptions.
2. If it is additional information that does not line up with the bar chart, consider using an INSET statement to add the information to the chart.
Hope this helps!
Dan
Hey Dan,
thank you for the ideas !!
The INSET statement works well.
But I have a problem with the size of the bar chart-box. My description is too big for it.
Perhaps their is an alternative to make the bar chart-box greater or to put the description outside of the graph.
Thanks,
Daniel
The best alternative for putting them outside the graph is to use multiple FOOTNOTE statements. To make the graph itself bigger, you can use the WIDTH and HEIGHT options on the ODS GRAPHICS statement.
Thanks!
Dan
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.