New Contributor
Posts: 3

# How to label certain points in a 3D scatter plot

I learned there are a similar post of "How to label certain points in a scatter plot", however this time I try to label some points in 3D scatter plot (PROC G3D)

this is the program I come up after l learned the post above

/* Set the graphics environment */
goptions reset=all border cback=white htitle=12pt;

/* Create data set WORK.NUMS using */
/* a set of randomly sampled points */
data nums;
keep x y z ID;
do i=1 to 30;
x=10*ranuni(33)-5;
y=10*ranuni(35)-5;
z=sin(sqrt(x*x+y*y));
ID = i;
output;
end;
run;
data labels;
length text \$2;
retain xsys ysys '2' hsys '3' function 'label' position '2' style '"calibri"';
set nums;
where y ge 2;
text = left(id);
run;
/* Define a title for the graph */
title1 'Scatter Plot of NUMS Data Set';

/* Generate the scatter plot */
proc g3d data=nums anno=labels;;
scatter y*x=z;
run;
quit;

However, when I turn to IRIS data, and label some points as well as their group, I have some troubles.

/* Create data set WORK.IRIS2 */
data iris2;
set sashelp.iris;
length Species \$12. Colorval \$8. Shapeval \$8.;
if species='Setosa' then
do;
shapeval='club';
colorval='vibg';
end;
if species='Versicolor' then
do;
shapeval='diamond';
colorval='depk';
end;
if species='Virginica' then
do;
colorval='dabg' ;
end;
run;

data labels1;
length text \$3;
retain xsys ysys '2' hsys '3' function 'label' position '2' style '"calibri"';
set sashelp.iris (rename=( PetalLength = y PetalWidth=x));
text = left(_N_);
run;
data labels;
set labels1;
where y GE 60;
run;

/* Define titles and footnotes for graph */
title1 'Iris Species Classification';
title2 'Physical Measurement';
title3 'Source: Fisher (1936) Iris Data';
footnote1 j=l ' Petallen: Petal Length in mm.'
j=r 'Petalwid: Petal Width in mm. ';
footnote2 j=l ' Sepallen: Sepal Length in mm.'
j=r 'Sepal Width not shown ';
footnote3 ' ';

/* Create the graph using a NOTE statement */
/* to create the legend */
proc g3d data=iris2 anno=labels;
scatter PetalLength*PetalWidth=SepalLength
/ color=colorval
shape=shapeval;

/* Create a legend using NOTE statements */
note;
note j=r 'Species: ' c=dabg 'Virginica '
j=r c=depk ' Versicolor '
j=r c=vibg 'Setosa ';
run;
quit;

I don't get the expected labelled point in the G3D graph, any helps?

thanks,

Super User
Posts: 13,583

## Re: How to label certain points in a 3D scatter plot

Please describe exactly what you mean by :

I don't get the expected labelled point in the G3D graph, any helps?

thanks,

Do you mean there are labels in the result you did not expect? Describe or list the labels you did not expect.

Are there expected labels not present (describe which ones are missing and the expected label)

Is the label present but the text incorrect?

Are there labels for points not present?

It is hard to address an expectation without understanding what is expected.

New Contributor
Posts: 3

## Re: How to label certain points in a 3D scatter plot

the first program is the label points I expect, I labelled all points with y greater than 2 by using their corresponding ID.

however, once the data is grouped into different categoies, as it is shown in the second program. There are three species in IRIS data, and they will be marked as three different color and shapes. In that case, if I want to label all points with y greater than 60 by using their corresponding ID, I can't get the label as the previous example.

Hopefully I clearly express my concern, any suggestion will be appreciated.

New Contributor
Posts: 3

## Re: How to label certain points in a 3D scatter plot

I FIGURE IT OUT.

WHEN PREPRAING THE ANNO DATA, WE HAVE TO CONSIDER 'Z' BESIDES X , AND Y,  SINCE IT IS A  3-D GRAPH.

data labels1;
length text \$3;
retain xsys ysys '2' hsys '3' function 'label' position '2' style '"calibri"';
set sashelp.iris (rename=( PetalLength = y PetalWidth=x SepalLength = Z));
text = left(_N_);
run;

Discussion stats
• 3 replies
• 378 views
• 0 likes
• 2 in conversation