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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 4 replies
  • 1214 views
  • 3 likes
  • 2 in conversation