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
Diamond | Level 26

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
Diamond | Level 26

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.

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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