BookmarkSubscribeRSS Feed
sundeep23
Obsidian | Level 7

Hi All,

            I am trying to create multilple graph with common legend. I got multilple graphs in to the pdf but I am stuck on how to create a common legend for sgplot . I got an example for gplot tp create a common legend  but not forsgplot. Can anyone help me on this.Thanks in advance.

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Have a look through this blog: http://blogs.sas.com/content/graphicallyspeaking/

It has examples of pretty much anything you can think of doing with graphs, generally provides sgplot and GTL code for each one.  GTL is probably easier.

sundeep23
Obsidian | Level 7

Thanks for the response.  I am trying to create 4 bar line charts with common legend I dont see any similar thing in that article.

Cynthia_sas
SAS Super FREQ

Hi:

  This might be better posted in the Graph forum. But I can easily control the legend when I run this code. I guess I don't understand what you mean by 4 "bar line" charts -- 1 bar and 4 lines? or...?

Cynthia

       

** run the code once with the KEYLEGEND statement and then;

** run it again without and you should see what the KEYLEGEND statement does;

ods listing;

proc sgplot data=sashelp.shoes;

  vbar product / response=returns stat=mean name='bar';

  vline product / response=inventory stat=mean name='inv' y2axis;

  vline product / response=sales stat=mean name='sal' y2axis;

  keylegend 'inv' 'sal';

run;

sundeep23
Obsidian | Level 7

Hi Cynthia

It is  4 graphs in one pdf page which need to have one common legend for all the 4 graphs .Not 4 lines and one bar in one graph.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Try layout lattice per: http://blogs.sas.com/content/graphicallyspeaking/2013/02/12/gtl-layouts/

That even shows common legend.

Cynthia_sas
SAS Super FREQ

Hi, Sounds like PROC SGPANEL to me. You can easily get 4 graphs on 1 page in a PDF file with 1 legend.

Cynthia

ods pdf file='c:\temp\_4graf.pdf';

proc sgpanel data=sashelp.shoes;

  where (product contains 'Dress' or

         product contains 'Casual') and

        region in ('Asia', 'Pacific', 'Canada');

  panelby product;

  vbar region / response=sales stat=mean group=region;

run;

ods pdf close;

sundeep23
Obsidian | Level 7

Hi Cynthia,

                  Its not a sgpanel procedure as I am creating a bar line chart I used Proc sgplot. It is similar to the below example but the only thing is I am not getting the common legend.

41461 - Put multiple PROC SGPLOT outputs on the same PDF page using PROC GREPLAY

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Not the top article in particular, it is a blog, so has many posts on different subjects.  You should however find an example there, try the search box for Legend, has many examples.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 3265 views
  • 0 likes
  • 3 in conversation