BookmarkSubscribeRSS Feed
davehalltwp
Quartz | Level 8

Greetings.

 

I have created a simple line plot using prog GPLOT.  The only thing I haven't finished is the legend.  I've always been bad at them, and usually convince people to accept them as is (I'm very peruasive, ha ha).  This time I am trying to improve.

 

The legend I want looks like this:

 

Treatment       * Superdrug     * Placebo

 

inside a box, below the plot.  The asterisks are circles of different colors.

 

Is that difficult?  

 

Here is the code I am currently developing.  Thank you, experts!

 

goptions reset=all  
         gsfmode=replace  
         cback=white 
         gunit=pct 
         rotate=landscape
         ypixels=2000 xpixels=2400 vsize=5in;

ods graphics on / width=9.4 in height=5.5 in noborder;
   
* -------- legend -------------- *;
*legend1 label = ('Treatment')
*        value = (color = black height = 1.5 'Superdrug  '     'Placebo    '  );

* -------- axes ---------------- *;
 
axis1 split  = '|' 
      label  = ('Time Point' h = 12pt)
	  order  = (1 2 3 4 5)
      minor  = none
	  value  = (h = 6pt)
	  offset = (3,3);

axis2 label  = (angle = 90 'Mean Serum TTR (mg/dL) +/- 1 Standard Error' h = 12pt)
      order  = (28 to 32 by 1)
      minor  = none
	  value  = (h = 6pt);

* -------- plot symbols -------- *;

** -- Superdrug -- **;
symbol1 interpol = hiloctj color = green line = 1;                  ** standard error **;
symbol2 interpol = none    color = green value = dot height = 1.4;  ** mean TTR       **;

** -- Placebo ----- **;
symbol3 interpol = hiloctj color = blue line = 2;                   ** standard error **;
symbol4 interpol = none    color = blue value = dot height = 1.8;   ** mean TTR       **;      

proc format;
     value visform 1 = 'Day 28 Pre-dose' 
                   2 = 'Month 3'
                   3 = 'Month 6' 
                   4 = 'Month 9'
                   5 = 'Month 12'; 
     run;

proc gplot data = adttr8;
     plot plotval1*avisitn  mean1*avisitn  plotval2*avisitn  mean2*avisitn / 
          overlay haxis = axis1 vaxis = axis2 /*legend = legend1*/;
	 format avisitn visform. ;
     run; 

 

 

 

 

 

5 REPLIES 5
ballardw
Super User

By "The asterisks are circles of different colors." do you mean the DOT that the SYMBOL statement is using in the plots or do you mean an actual circle?

 

Something like this:

legend1 label=(position=(bottom left) "Treatment") across=2
        value=('Superdrug' 'Placebo')
;

would attempt to use the plot symbols in the legend. But when you have 4 plot statements then getting legends to align can be a bit difficult.

 

Typically you it would be a better idea to arrange a variable that indicates the plot result instead of two plot statements:

Instead of something like:

 plot mean1*avisitn  mean2*avisitn

would be

Plot mean*avisitn=groupvar

Where Groupvar would hold information like 'Superdrug' or 'Placebo'.

Data would look like

mean avisitn groupvar
.5       1         Superdrug
.4        2        Superdrug

You might find that the separate legend ends up not even needed if the data is built and better options for the plot data.

 

Or you can look here for what sounds a lot like the same homework from a few years ago where that questioner wanted something a bit more specific that required the annotate facility to draw images and set text:  https://communities.sas.com/t5/Graphics-Programming/GPLOT-Legend-Style/td-p/459544

davehalltwp
Quartz | Level 8

Thank you, Ballard.

 

What I ended doing, after going to the millionth page of a Google search and finding this:

 

http://support.sas.com/kb/46/723.html 

 

I used this Legend statement:

legend1 order=('Superdrug' 'Placebo') label = ('Treatment') frame;

I also had to rename two variables, plotval1 and plotval2, to Superdrug and Placebo, respectively.  Weird, but it seems okay.  I couldn't get the circle plot symbol (when I used the variables that have that symbol associated, I three circles each), but my legend has the green solid line and blue dashed line to match the plot, and even has "Treatment" in it.  I think it will be okay.

 

The other problem that I might attack tomorrow is the spacing on the X axis.  the values are 28, 91, 183, 274 and 365 (for VISITN, or visit day).  I thought they would be spaced according to the value (ie, a smaller gap between 28 and 91 than between 91 and 183.  But for some reason they are treated as discrete values and spaced evenly.

 

I would prefer this:

---- 28--------- 91----------------------183 ---------------------- 274 ---------------------- 365

 

I got this:

---- 28---------------------- 91----------------------183 ---------------------- 274 ---------------------- 365

 

 

 

 

 

 



 

Madelyn_SAS
SAS Super FREQ

Questions about GPLOT should be posted to Programming > Graphics Programming.

davehalltwp
Quartz | Level 8

Okay, sorry, Madelyn.  

 

FYI, world, I finally gave in and switched to use SGPLOT, and solved 99.9% of my issues.

Madelyn_SAS
SAS Super FREQ

No worries! I only mentioned it because the Graphics community is a better place to engage the graphics coding experts. 

sas-innovate-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

Register now!

Tips for filtering data sources in SAS Visual Analytics

See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 351 views
  • 1 like
  • 3 in conversation