Subscribe Bookmark



Jun 9, 2012

New in JMP 12: Data Table support for images (part 2)

Author’s note: Today’s example applies to a map created in Graph Builder, but you can use this approach in the majority of platforms in JMP.

In part one of this two-part series, I showed an example of the support for images in data tables in JMP 12. Today, I’ll show you how this capability allows you to create multilayered reports and graphs in Graph Builder, with just a bit of scripting.


In the map above, each state is colored by its average temperature — blue is cooler, red is warmer. Hovering over any state reveals a graph of the state’s temperature trends over time. Here, we have the best of both worlds: an easily digestible overview of the data, with additional details hidden but immediately available.

Graph Builder in JMP allows us to save images of the graphs it creates to data tables, but the trend graph above was not created in Graph Builder — it was created using Overlay Plot. What happens when we want to save images we created outside of Graph Builder?

Fortunately, a bit of JSL is all we need. In today’s example, we will walk through the code needed to create a map like the one above.

First, let’s look at the raw data: average annual temperatures for each of the 50 states in the US. This is our source table, and will be used to create the trend plots.


The map itself relies on the table below. To create it, we will:

  • Summarize the original table, averaging temperatures by state.
  • Create a new column, of Expression data type, to house the images of the trend plots created from the original table.
  • Copy the images from each of the trend plots into the summary table.
  • Turn on labeling for the State and Mean(Temp F) columns, to reveal these when we hover on the map.
  • Pic7

    Step by step, here is what it looks like in JSL.


    • Line 1 assigns a handle to the source table.
    • Lines 3 – 11 create the overlay plot report.
    • Line 13 assigns a handle to the overlay plot, so we can reference the individual outline boxes within it.
    • After running the code above, the report looks like this. (If your report differs, it could be due to differences in our preference settings.)


      The next four lines of JSL create the summary table and prepare it for use with the images.


      • Line 15 creates the summary table.
      • Line 17 deletes the N Rows column from the summary table.
      • Line 19 creates a new column, Graph, of expression data type.
      • Line 21 turns on the column labeling properties for the State and Graph columns.
      • All that remains is to loop through the report, saving the pictures to the summary table.


        • After initializing our counter in line 23, we cycle through a loop. Since the 1 in line 25 always evaluates to “True”, we will need to have a way to break out of the loop when we need to. The Try ( … , … ) statement lets us do that.
        • Try ( … , … ) will attempt to process whatever code appears before the comma. If an error is encountered, it processes the code after the comma (or just ignores the error, if there is no code after the comma—the second argument is actually optional.)
        • Here, line 27 attempts to get a handle on the current outline box in the report, while line 28 takes a picture of that outline box, and stores the picture in the current row of the summary table. Since the summary table and the report both sort the states in alphabetical order, this simple approach works.
        • Line 32 increments the index, so that the next time through the loop, we attempt to get the next outline box. Eventually the index hits 51, and since Rep[Outlinebox(51)] does not exist, we get an error and move into the 2nd half of the Try ( … , … ) statement, exiting the loop via the Break ().
        • The summary table should now look like this:


          To create the map, invoke Graph Builder and drag the State and Temperature columns to the Shape and Color zones, respectively. That’s all there is to it!


          I hope you have enjoyed today’s post; I am excited to see and hear about the interesting applications you will come up with!

          P.S. I’ve placed the source table and script file in the JMP User Community’s File Exchange. (A free SAS profile is needed to access the files.)