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;
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
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
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
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.