BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

Hi,

I've got a stored process running on SPWA which uses ODS HTML to make box plots, and would like to allow a user to click a box to drill down to detailed data behind that box.

In the docs, it looks like the URL= option is supported by BarChart, BubblePlot, ScatterPlot, and others, but not poor little BoxPlot???

So was thinking I would try something silly, like overlay an invisible scatterplot of means on top the box plot means, and use URL= in the scatter plot.  So if a user clicked the mean displayed on the box plot, the drill-down would work, because they would be clicking the invisible scatterplot.

But before I proceed with that hack, wanted to ask for any better suggestions.

Thanks,

--Q.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

Your idea is not "silly" at all, as using "Building-blocks" is the cornerstone of GTL and SG Procedures.  If you cannot find a feature in a plot statement, you can often overlay another to get the job done.

I am assuming your box plot has discrete values for the category variable. Your idea will work just fine, but another way may be to overlay a transparent bar chart on the box which covers the entire height.  Here I left the transparency to 80% just to see the bars.  If you have interval category axis (SAS 9.3), I am sure we can use a HighLow plot instead.

Note, this will work because you are using GTL.  SGPLOT does not allow overlay of other plot types on top of BOX, something we will fix soon.

data cars;
  length URL $25;
  set sashelp.cars;
  max=60;
    if type eq 'Sedan' then URL='http://www.sas.com';
    else URL='https://support.sas.com';
run;


proc template;
  define statgraph BoxURL;
    begingraph;
      layout overlay;
        boxplot x=type y=mpg_city;
        barchart x=type y=max / url=url datatransparency=0.8 stat=mean;
     endlayout;
   endgraph;
  end;
run;

ods html file='BoxURL.htm'  path='c:\';
ods graphics / reset imagemap=on width=5in height=3in imagename='BoxURL';
proc sgrender data=cars template=BoxURL;
run;
ods html close;

View solution in original post

7 REPLIES 7
GraphGuy
Meteorite | Level 14

One alternative would be to create the boxplot using Proc Gplot and Annotate.

This technique is described in detail in Example 10 (p. 65) in my book "SAS/Graph: Beyond the Basics".

Here is some example output (where you can see that you can have href links ... although I don't really link them to anything), and a link to the SAS code:

Annotated Horizontal Boxplot

http://robslink.com/SAS/book/example10_info.htm

Quentin
Super User

Thanks Rob,

I feel like for this plot I'm in too deep to SGRENDER to back out now.  But as your book is sitting on my desk, I appreciate the reference, and if things slow down may try rewriting it in GPLOT.  Could be a helpful learning experience to try making the same plot in both.

--Q.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Jay54
Meteorite | Level 14

Your idea is not "silly" at all, as using "Building-blocks" is the cornerstone of GTL and SG Procedures.  If you cannot find a feature in a plot statement, you can often overlay another to get the job done.

I am assuming your box plot has discrete values for the category variable. Your idea will work just fine, but another way may be to overlay a transparent bar chart on the box which covers the entire height.  Here I left the transparency to 80% just to see the bars.  If you have interval category axis (SAS 9.3), I am sure we can use a HighLow plot instead.

Note, this will work because you are using GTL.  SGPLOT does not allow overlay of other plot types on top of BOX, something we will fix soon.

data cars;
  length URL $25;
  set sashelp.cars;
  max=60;
    if type eq 'Sedan' then URL='http://www.sas.com';
    else URL='https://support.sas.com';
run;


proc template;
  define statgraph BoxURL;
    begingraph;
      layout overlay;
        boxplot x=type y=mpg_city;
        barchart x=type y=max / url=url datatransparency=0.8 stat=mean;
     endlayout;
   endgraph;
  end;
run;

ods html file='BoxURL.htm'  path='c:\';
ods graphics / reset imagemap=on width=5in height=3in imagename='BoxURL';
proc sgrender data=cars template=BoxURL;
run;
ods html close;

Quentin
Super User

Thanks much Sanjay,

I agree, I like the invisible barchart overlay approach better than scatterplot, because the user doesn't have to try to click exactly on the mean.

Unfortunately in my case I have some plots where we do not show the y-axis origin, and the invisible barcharts foce the y-axis to show the origin.

But more importantly, glad the approach sounds sensible, and appreciate your sharing example code.

--Q.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Jay54
Meteorite | Level 14


Not a problem.  I suggest use the HIGHLOW statement instead.  You can set the low and high values to the Q1 and Q3 (or the min and max values of data for each category). This will avoid bringing in the "zero" value.

This works.  One thing to consider will be that HIGHLOW will plot each observation, not a summary as does bar.  So, I would only add the min and max values for one (I did it for the last one) observation in each type, and leave the other ones missing.  Nothing bad will happen if you don't do this when all bars are fully transparent, but you will have many overlays.  Here is the graph with faint HighLow bars:

BoxURL1.png

Quentin
Super User

Excellent point.  I didn't realize that HIGHLOW plots could become bars, like floating bar charts.  But there it is on page 110 of your SG book, "HighLow Bar Chart".  That's exactly what I should be doing (with GTL rather than SGPLOT).

Thanks again,

--Q

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Jay54
Meteorite | Level 14

Yes, and you can guess at a lot of other GTL features from the SG book.  Smiley Wink  This will make for a good article on the blog.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1869 views
  • 3 likes
  • 3 in conversation