- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Is there a good way to create an independent legend that you can use for multiple graphs in Enterprise guide 5.1 SAS 9.2? So that all graphs use the same color schema and the legend is only shown once?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
David, I have presented a paper that shows you how you can plot your own legend:
http://www.lexjansen.com/pharmasug/2014/DG/PharmaSUG-2014-DG13.pdf
Otherwise, I agree with @ballardw suggestion to create a consistent legend.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The ability to assign graphic attributes to values across procedures was one of the major additions to SG graphics in 9.3. In 9.2 careful ordering of the categorical variables, something ensuring they appeared with a missing or 0 value depending on the procedure usually let me do this IF I pre-summarized the data. A sum of one value is that value ...
The legend issue, assuming you can get the color schema to work, might be the option NOAUTOLEGEND on the procedures where you don't want the legend to appear.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This article might do the trick still playing with it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
David, I have presented a paper that shows you how you can plot your own legend:
http://www.lexjansen.com/pharmasug/2014/DG/PharmaSUG-2014-DG13.pdf
Otherwise, I agree with @ballardw suggestion to create a consistent legend.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you really want the result as in the linked sample, and not just an independent legend, proc SGPANEL is perfectly suited for this. It would produce a common legend, all in probably 4-5 lines of code. Use same data set as in the sample program. Should work with SAS 9.2.
ods graphics / reset width=5in height=3in attrpriority=color';
proc sgpanel data=one;
panelby grp;
series x=x y=y / group=z markers;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
In my particular case I need to charge the scale between the various graphs. It looks like sgpanel provides one scale for multiple graphs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can set the UNIFORM option to get different scaling when the axis is not shared.
Else, you can use proc SGSCATTER with PLOT statement to get fully independent plots cells.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I need to include different where clauses to include different subsets of data. Sgpannel has the group clause however it does not have the option to manually specify different subsets.
E.g. only show summation total, show all possibilities.
I’m comparing similar graphs using line charts and bar graphs. Sgscatter is for scatterplots.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Actually. if you use the JOIN option on the PLOT or COMPARE statements in SGSCATTER, you can get line plots as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Could you post a link to an example of sgscatter using a line graph without the typical scatter plots? I am using a summation clause in my current plots, the sgscatter functions appear to be for plotting data points rather than summations. The compare feature compares two columns, I am trying to compare two different subsets using a where clause.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here are some simple examples:
proc means data=sashelp.class;
class age;
var weight height;
output out=temp mean=;
run;
proc sgscatter data=temp;
plot (weight height)*age / join;
run;
proc sgscatter data=temp;
compare x=age y=(weight height) / join;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Can I use the same procedure to do:
Graph 1
line for the weight for age 11
line for the weight for age 12
line for the weight for age 13
Then beside it using the same legend
Graph 2
line for the weight for age 14 only including where mean > 55
line for the weight for age 15 only including where mean > 55
line for the weight for age 16 only including where mean > 55
In other words can I use where clause like functions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I’ve been working off of djrisks’ paper. I was able to use it to create an independent series plot. I’m currently working on adding manual sorting and coloring to the legend. Note that the base part of the code is this: the additional grouping is not needed for most situations.
data enroll_led;
set enroll_le;
index_final = _n_;
run;
data legend;
set enroll_led;
/* For patient legend */
do i = 6, 10;
xax = i;
output;
end;
drop i;
run;
ods graphics on / reset = all border = off imagefmt = png width = 3in height = 2in imagename
= "grlegend";
goptions reset = all;
proc template;
define statgraph order;
dynamic TITLE1 TITLE2;
begingraph;
entrytitle TITLE1;
entrytitle TITLE2;
layout overlay / xaxisopts =(display = NONE) yaxisopts = (display = NONE)
y2axisopts = ( display = STANDARD reverse = true label = " "
linearopts= ( tickvaluesequence=(start=1 end=32 increment=1)));
/* Main plot */
seriesplot x=xax y= degree_level / yaxis = y2 display = all group=degree_level
index = index_final lineattrs = (pattern =1 thickness = 1) /*markerattrs = (size = 1pt)*/;
endlayout;
endgraph;
end;
run;
proc sgrender data= legend template=order;
dynamic title1=" ";
dynamic title2="Legend";
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
David, I'm pleased my paper helped you! For clarification, what would you like to do now?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
My overall goal which now is achievable given your paper, a bit of additional research, and proof of concepts; is to have a legend for a number of small dynamic dashboard graphs. The legend needs to match the colors displayed on the graphs. The graphs need to change display sets based on input values affecting their where clauses. The legend needs to have a predefined order that is non-alphabetical.
My plan is create a hardcoded color pattern set.
Assign the color pattern set to the legend.
Order the legend by a database index key.
Make the legend only show the colors that are currently being used.
Sort the dataset and assign the color pattern to the dataset each time I change data subsets, when input values are changed. (This is inefficient but appears to be the best way).
Add line charts (sgplot) and barcharts (gcharts)
I’m using SAS 9.2 and EG 5.1