Data visualization with SAS programming

How to label a certain point in a scatter plot?

Reply
Contributor
Posts: 22

How to label a certain point in a scatter plot?

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: 

 

DATA work.cereal;
INFILE "/folders/myfolders/cereal.txt"
DLM=',' FIRSTOBS=2 DSD MISSOVER;
INPUT Name :$50. Manufacturer $ Type $ Calories Protein Sodium Fiber Carbohydrates Sugars Potassium Vitamins Weight Cups;
RUN;

PROC PRINT DATA=work.cereal;
RUN;

ODS GRAPHICS ON;

PROC SGPLOT DATA=cereal;
SCATTER X=Sugars Y=Carbohydrates;
XAXIS GRID VALUES=(0 TO 15 BY 3);
YAXIS GRID;
INSET 'Quaker Oatmeal' / POSITION= BOTTOMLEFT;
TITLE 'Sugars vs Carbohydrates of Cereals';
RUN;
Super User
Posts: 22,874

Re: How to label a certain point in a scatter plot?

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;
Super User
Posts: 13,084

Re: How to label a certain point in a scatter plot?

 

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?

 

 

Ask a Question
Discussion stats
  • 2 replies
  • 123 views
  • 1 like
  • 3 in conversation