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: 980

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.

Frequent Learner
Posts: 1

Re: scatter plot with mouse-over

Can the html statement be used with proc sgscatter? I keep trying to add it to my code and I throw an error no matter where I place it. Please advise.

 

data case_provider;
set centurion_physician;
length myhtml $ 250;
if nurse_traffic ~=. then provider_type="Nurse Practitioner";
if physician_traffic ~= . then provider_type= "Physician";

myhtml='title='||quote(
"Provider: "||strip(provider_type)||" "||trim(left(pcp_name))||'0D'X||
"Unique Cases: "||trim(left(unique_cases))||'0D'X||
"Unique Consults: "||trim(left(unique_consults))||'0D'X||
"Total Consults: "||strip(total_consults)||'0D'X||
"Cases Missing Site Detail: "||trim(left(missing_site_ct))
)
||' '|| 'href="'||"&hardcoded_drilldown"||'"';

run;

title "Utilization and Response Times by Provider Type";
proc sgscatter data=case_provider;
plot (unique_cases provider_type )*avg_response_hours / colorresponse=avg_response_hours

markerattrs=(symbol=CircleFilled size=14)

filledoutlinedmarkers
colormodel=(CX3288BD CX99D594 CXE6F598 CXFEE08B CXFC8D59 CXD53E4F);

label unique_cases ="Unique Cases" avg_response_hours= "Average Response Time in Hours"
;

run;
quit;

Ask a Question
Discussion stats
  • 4 replies
  • 759 views
  • 0 likes
  • 4 in conversation