BookmarkSubscribeRSS Feed
rileynic
Calcite | Level 5

Hi,

I am producing scatter plots with sgplot, and I am placing a vertical reference line on the graph.  In the legend, the symbol and legend label correctly appear for the scatter plots (a red dot followed by VO2), but I would like to hide the symbol for the vertical reference line.  Currently my legend for the vertical line shows a dotted black line followed by EX = Exercise, but I want to hide the dotted black line.  Any ideas?

proc sgplot data=cpet15;

  keylegend "vo2" "ex" / border location = inside position = topleft down=4 opaque;

  xaxis label="Time (min)" /*min=0 max=1 */;

  yaxis label="VO2 and VCO2 (ml/min)" /*min=0 max=1 */;

  y2axis label="Work (Watts)" min=0 max=300 ;

  /*VO2 vs time*/

  scatter x=t15_c_min y=ex_vo2 / LEGENDLABEL = "VO2" name = "vo2" MARKERATTRS= (symbol=circlefilled color=red size=6pt);

  /*vertical reference line*/

  refline 5  / axis=x label = "EX" labelloc = inside labelpos = min legendlabel = "EX = Exercise" name = "ex" lineattrs = (pattern=4);

run;

4 REPLIES 4
DanH_sas
SAS Super FREQ

Instead of putting the reference line in the legend, what if you used the INSET statement to add this information to the graph? You can also position the inset information, or let it automatically move to avoid collisions.

INSET "EX = Exercise";

Hope this helps!

Dan

rileynic
Calcite | Level 5

that seems to have some potential...I will play with it...do you think I can that red dot and VO2 from the scatterplot in the inset box too?

thanks for your quick response!

nicole

DanH_sas
SAS Super FREQ

No, insets do not take plot references. They are for adding additional textual information (either as prose or a table) to the inside of a plot area.

Looking at your code further, let me make another recommendation. You have one plot with no group variable and one reference line (with a label to identify it). Having a legend might not benefit you that much. It seems that having your graph title mention something about "plotting VO2" would take care of the scatter plot description and adding a footnote for "EX = exercise" would take care of the reference line label. That way, you maximize the plot area for just the data.

Hope this helps!

Dan

rileynic
Calcite | Level 5

actually, i have 3 scatter plots on this graph and 4 vertical reference lines, so I do need a legend...but I am happy that you have introduced me to the inset statement. I now have 2 options:

- I can include the legend values and symbols for the vertical reference lines in the legend

OR

- I can add the legend values without their symbols to the graph using the inset statement

this has been very helpful!

thanks,

nicole

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1566 views
  • 3 likes
  • 2 in conversation