Data visualization with SAS programming

SGRENDER box plot with drill-down

Accepted Solution Solved
Reply
Trusted Advisor
Posts: 1,151
Accepted Solution

SGRENDER box plot with drill-down

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.


Accepted Solutions
Solution
‎02-28-2013 12:07 PM
SAS Super FREQ
Posts: 1,044

Re: SGRENDER box plot with drill-down

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


All Replies
SAS Employee
Posts: 963

Re: SGRENDER box plot with drill-down

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

Trusted Advisor
Posts: 1,151

Re: SGRENDER box plot with drill-down

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.

Solution
‎02-28-2013 12:07 PM
SAS Super FREQ
Posts: 1,044

Re: SGRENDER box plot with drill-down

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;

Trusted Advisor
Posts: 1,151

Re: SGRENDER box plot with drill-down

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.

SAS Super FREQ
Posts: 1,044

Re: SGRENDER box plot with drill-down


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

Trusted Advisor
Posts: 1,151

Re: SGRENDER box plot with drill-down

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

SAS Super FREQ
Posts: 1,044

Re: SGRENDER box plot with drill-down

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.

Post a Question
Discussion Stats
  • 7 replies
  • 712 views
  • 3 likes
  • 3 in conversation