04-12-2018 05:53 PM
I am trying to label the point in the scatter plot with the smallest carbohydrate content, but so far I just have entered some text in the bottom left of the graph.
Here it is my code and the data set:
DLM=',' FIRSTOBS=2 DSD MISSOVER;
INPUT Name :$50. Manufacturer $ Type $ Calories Protein Sodium Fiber Carbohydrates Sugars Potassium Vitamins Weight Cups;
PROC PRINT DATA=work.cereal;
ODS GRAPHICS ON;
PROC SGPLOT DATA=cereal;
SCATTER X=Sugars Y=Carbohydrates;
XAXIS GRID VALUES=(0 TO 15 BY 3);
INSET 'Quaker Oatmeal' / POSITION= BOTTOMLEFT;
TITLE 'Sugars vs Carbohydrates of Cereals';
04-12-2018 06:04 PM
I prefer using the TEXT or MARKERCHAR statements.
Here's a quick example, it labels the oldest kid in the SASHELP.CLASS data set.
proc sort data=sashelp.class out=class; by descending age; run; data class_text; set class; if _n_=1 then text_value = "Oldest Kid"; run; proc sgplot data=class_text; scatter x=weight y=height; text x=weight y=height text=text_value; run;
04-12-2018 06:34 PM
One way would be create an annotate data set with the location variables and appropriate instructions to display and reference that set using the SGANNO= option on the Proc statement.
The SCATTER statement supports providing a value label to markers using the DATALABEL option. If you use DATALABEL=variablename it will use the value of the variable to label the marker.
So another way would be to determine that value and then add a variable that has a value only for the records of interest to your plot dataset to reference in the scatter plot.
So what do you want the label to be? The numeric value of the point? The value of a different variable? if so which?