Data visualization with SAS programming

scatter plot with mouse-over

Reply
New Contributor SQU
New Contributor
Posts: 2

scatter plot with mouse-over

Hi,

I have a scatter plot of weight versus height, and mouse-over can show weight and height numbers for each observation, but I'd like to show more than just x and y; I want to see name and age as well.

The code is below. Any help will be greatly appreciated.

Thanks,

SQU

ods listing close;

ods html file="c:\temp\pie.html" (title="Weight-Height Scatter Plot")

nogtitle nogfootnote style=statdoc gpath="c:\temp\";

goptions reset=all

goptions device=Java;

symbol i=none value=plus r=100000;

data test;

infile datalines dlm=',';

input name $ Sex $ age height weight;

datalines;

Alfred,M,14,69.0,112.5

Alice,F,13,56.5,84.0

Barbara,F,13,65.3,98.0

Carol,F,14,62.8,102.5

Henry,M,14,63.5,102.5

James,M,12,57.3,83.0

;

run;

proc gplot data=test;

      plot height * weight;

run;

quit;

goptions reset=all;

ods html close;

ods listing;

SAS Employee
Posts: 967

Re: scatter plot with mouse-over

I see you're using device=java ... in SAS/Graph, device=java (or activex) typically show the values being plotted, by default.  To have custom chart-tip hover-text, you can put your custom text in a variable in your data set (coded a special way as html title= or alt= tags), and then use the gplot "html=" option to point to that variable.

Also, I usually use device=png (or gif) for custom chart tips.  Device=java (or activex) might or might not support the custom text, depending on which version you are using (and possibly depending on exactly how you set up your variable).  Too many unknowns for me, so I use png.

Here is a simple example:

http://robslink.com/SAS/democd23/scat.htm

http://robslink.com/SAS/democd23/scat_info.htm

And here is the important bit of the code:

data mydata; set mydata;

length htmlvar $500;

htmlvar=

'title='||quote(

  'State: '||trim(left(st))||'0D'x||

  'Population: '||trim(left(put(population,comma12.0))))||

' href="http://www.state.'||trim(left(lowcase(st)))||'.us"';

run;

proc gplot data=mydata;

plot population*st=1 /

haxis=axis1 vaxis=axis2 vzero

html=htmlvar;

run;

Occasional Contributor
Posts: 16

Re: scatter plot with mouse-over

Hi:

  Just wondering if you noticed the posting https://communities.sas.com/thread/38666. It shows how you can build on Robert's code in the reply above to include information other than a link in a mouse over.

Bill.

New Contributor SQU
New Contributor
Posts: 2

Re: scatter plot with mouse-over

Thank you, Bill. That's helpful.

Ask a Question
Discussion stats
  • 3 replies
  • 663 views
  • 0 likes
  • 3 in conversation