Forest Plot with Subgroups

During SAS Global Forum 2012, I had conversations with many SAS users who wanted to create Forest Plots.  However, there was one new twist.  The study names were subgrouped by categories like 'Age', 'Sex', etc., with multiple entries under each subgroup.  The name of each study within the subgrouped was indented to indicate the grouping.

This also came up in a recent discussion with the folks at CTSPedia, who also wanted to create a similar subgrouped forest plot shown below (click on graph for bigger version):

The graph itself can be easily created using GTL, but the main issue was the indentations needed in the subgrouped study names.  In GTL and SG Procedures, leading and trailing blanks are removed from the axis tick values and  markercharacter strings.  So, how do we include the indentations?

Earlier, I discussed using a non breaking space for a simple Forest Plot using SGPLOT procedure.   In that article I also provided a sneak preview of this graph.   It looks like this nbsp is becoming my good friend.

Here we are using nbsp in place of a regular space for both the leading and trailing blanks.  To help get the indentations right in the dataset, I first use  a dot for all leading and trailing blanks in the study names.  These are easier to see.  Then, I simply replaced all dots by an nbsp ('A0'x) using the translate() function.  Remember, we have to use a non-proportional font to ensure the all characters have consistent width.

Here is the graph I created using SAS 9.2 release.  Note:  I did not receive the actual data set for the original graph, so the values for Mean LCL and UCL are eyeballed from the graph above and may not be very accurate.  The focus of the exercise is making the graph, given the data.

The code will be familiar to the GTL programmer.  Here are the basic steps for the template:

  1. Use a LAYOUT LATTICE with four columns for the main graph.
  2. Weights for the columns are (0.23 0.07 0.4 0.3).
  3. The study names are displayed in the first column using SCATTERPLOT with the MARKERCHARACTER option.  A non-proportional font is used to display these strings.
  4. The number of patients and % are shown in the second column also using the scatter plot with marker character option.  In this case, a non-proportional font is not necessary.
  5. The Hazard Ratio plot is shown in the third column with custom x axis tick values and label.
  6. PCI, Group and p-values are shown in the last column.
  7. For arranging the headers correctly, I used another 2x4 lattice, with slightly different weights and populated each cell with the string needed.

In such cases where the plot and data are aligned horizontally across a wide graph, it is helpful to provide a guide to the eye to keep things lined up across the page.  Something similar to the old 132 character line printer page with the green bands is helpful.  So, I used a trick to draw wide grid lines behind alternate blocks of observations.  I also added a background color for the headers.  Here is the graph:

In the graph above, the bands help the eyes track the data across the wide page.  In the graph above, I used the scatter plot with the marker character option to do all the textual columns, including the study names on the left.  This allowed me to put the shaded bands behind the full width of the graph.

An earlier version of this same Forest Plot is posted on the CTSPedia page.  In this graph, the study names are Y axis tick values.  The bands (using reference lines) cannot extend under the Y axis tick values.

Using SAS 9.3, the serifs for the error bars can be eliminated by using a HIGHLOWPLOT statement to plot the confidence interval.

Full SAS 9.2 program:  ForestPlot_92

Full SAS 9.3 program:  ForestPlot_93

 

tags: Dot Plot, Forest Plot, Layout Lattice, Marker Character, NBSP, non-proportional Font, Scatter Plot, Subgroups

5 Comments

  1. Posted October 16, 2012 at 9:35 am | Permalink

    Thank you Sanjay, this is really helpful!

    Kriss

  2. John O'Leary
    Posted October 31, 2012 at 12:51 pm | Permalink

    We are frequently looking to create forest graphs for clinical publications and the work you have Sanjay is very helpful. THANKS and keep up the great graphical work you are doing.

  3. Anca
    Posted November 29, 2012 at 11:08 am | Permalink

    Thank you!
    I've been looking for a way to indent a forest plot for months!
    :-)

    Thank you for sharing!!!!

  4. Stephen
    Posted October 16, 2013 at 11:51 am | Permalink

    Hi Sanjay,

    Many thanks for the excellent article.

    I have problems though when I want to have two rows with the same subgroup. For example if I twice write yes or no (for different subgroups), then only one is shown. Presumably this is due to the scatter.

    Is there any way to solve this?

    Many thanks

  5. Reza
    Posted April 8, 2014 at 5:03 am | Permalink

    Dear Sanjay,
    I'd like to plot 3 contiguous (all side by side and separated by one vertical line) subgrouped forest plots (corresponding to 3 methods). They have the same subgroups labels on the left side. Is there a mean to do this ? Thank you very much in advance for your advices.
    Best

2 Trackbacks

  1. [...] addition to the Forest Plot with Subgroups, another popular graph in the clinical research space is the Most Frequent Adverse Events Sorted by [...]

  2. [...] asking for the link to the subgrouped Forest Plot with bold headings.  She was referring to this Forest Plot with Subgroups  I had posted earlier.  However, as you can see, while the subgroup values are indented from the [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <p> <pre lang="" line="" escaped=""> <q cite=""> <strike> <strong>