Clinical Graphs: Spider plot


A Spider Plot is another way of presenting the Change from Baseline for tumors for each subject in a study by week.  The plot can be classified by response and stage.  Another way of displaying Tumor Response data was discussed earlier in the article on Swimmer Plot.

spiderThis article is prompted by a question on the SAS communities page on how to create a Spider plot.  The user provided an illustration of what the plot might look like. I followed the example and generated some data to create the graph shown on the right.  Click on the graph for a higher resolution view.

The data is arranged in six columns.  Four columns are needed to draw the progression of the disease for each subject over time:  Subject, Week, Change, RGroup.

spider_dataTwo additional columns are used to display the status at the end of the curve for each subject: WeekS, TGroup.  The first three observations are just to ensure the groups are assigned colors in the order we want.  A Discrete Attributes Map can be used, but I ran into some minor difficulties, so I skipped that step.  This exercise hepled reveal a minor problems, but I was able to work around it.

In this case, WeekS=Week+2 in this case, to position the marker at the right of the curve.  Only the last point in the curve has this nonmissing value.

The SAS 9.4M2 options for coloring the series and markers by another classifier (GroupLC and GroupMC) is used to color each curve for the Subject by the Response Group (RGroup).  Note, the connectivity for each curve is determined by setting Group=Subject.  Then, with in this, the color of each curve is set by setting GroupLC=RGroup.  This allows multiple curves to be classified in the same category.

The SAS 9.40M1 SymbolChar statement is used to define a few symbols to represent the status of each Subject, such as "Treatment Ongoing" etc.  These are inserted into the group symbols list using the DataSymbols option.  Custom group data colors are set using the DataContrastColor option.

A Scatter plot is used to display these markers.

SAS 9.4M2 SGPLOT Code:

title "Tumor Response by Week";
ods graphics / reset width=5in height=3in imagename='Spider';
proc sgplot data=spider noborder tmplout='c:\';
  format tgroup $growth.;
  symbolchar name=ongoing char='2192'x / scale=1;
  symbolchar name=growtht char='2020'x / scale=1;
  symbolchar name=growthnt char='2021'x / scale=1;
  styleattrs datacontrastcolors=(green gold red)
                    datasymbols=(ongoing growtht growthnt );
  refline 0 / lineattrs=(pattern=shortdash);
  series x=week y=change / group=subject grouplc=rgroup groupmc=rgroup
             markers markerattrs=(symbol=circlefilled)
            lineattrs=(thickness=2 pattern=solid) name='a';
  scatter x=weekS y=change / group=TGroup markerattrs=(size=16 color=black)
           nomissinggroup name='b';
  keylegend 'a' / title='Response' type=linecolor valueattrs=(size=7)
            location=inside position=topright across=1 opaque;
  keylegend 'b' / valueattrs=(size=7) noborder;
  xaxis label='Week';

There are also examples of Spider plots with negative date values on the x-axis.  These appear to track the disease state before and after start of treatment.  The above code will likely work if the data itself includes values from before start of treatment and the baseline value is 1.0.

Full SAS 9.4M2 SGPLOT code:  spider


About Author

Sanjay Matange

Director, R&D

Sanjay Matange is R&D Director in the Data Visualization Division responsible for the development and support of the ODS Graphics system, including the Graph Template Language (GTL), Statistical Graphics (SG) procedures, ODS Graphics Designer and related software. Sanjay has co-authored a book on SG Procedures with SAS/PRESS.


    • Sanjay Matange
      Sanjay Matange on

      The name is likely relevant for the domain. Just like a "Waterfall" chart for Oncology is essentially a bar chart. 🙂

  1. Thank you for sharing this with us. Very useful. But I have a question here: is it possible to show the legend as lines instead of squares with different colors? The grouping uses line color attribute not the line style, so it won't work if I change the type= option in the keylegend statement to 'line'. But is there any other way to make such change? Thanks!

    • Sanjay Matange
      Sanjay Matange on

      Yes, that is doable. First I thought you could just change the TYPE=LINECOLOR in the KEYLEGEND to TYPE=LINE. But that did not work since then you get all 5 lines in the legend since each has a different GROUP. So, an "elegant hack" is to change the appearance of the color block into a color line. You can do that by using the FILLHEIGHT, FILLASPECT and AUTOOUTLINE options.
      keylegend 'a' / title='Response' type=linecolor valueattrs=(size=7) autooutline
      location=inside position=topright across=1 opaque fillheight=3 fillaspect=5;

    • Dan Heath

      In SAS 9.3, the SYMBOLCHAR and STYLEATTR statements are not available to you. You would need to create a small ODS style that inherits from the main ODS style to override the group colors and markers. The rest of the code should work fine.

  2. Krishna Honest on

    I need to display graph as below :
    This figure presents the spider plot of individual changes from baseline in MDS-UPDRS part III total score over time by treatment group. All treatment groups will be displayed in the same figure. Different line types and color will be used to identify the treatment groups.
    Axis labels:
    • X-axis: Time Points(mins)
    • Y-axis: MDS-UPDRS part III total score

    I don't have rgroup variable. I have atptn(time points) and chg(change from baseline) variables with subject and treatment level info.

    I have tried using above given code but I do have 4 treatments in data so what will be value for 4th treatment in symbolchar statement. Moreover can I use proc template to define characteristic of treatment groups?

  3. Hello Sanjay, how can I higlight one group shading the others ? I have only one line "series" and do not use an attrmap since I have an issue with it for colours.
    Thank you in advance.

  4. Hi Sanjay,
    Very informative.
    Just wanted to know what if we wanted to show the dots for each time point as different for each line and use the same for legend. right now you have circles in body and squares for legend.
    will appreciate your feedback.


    • Dan Heath

      Hey Raj, the key here is that he has TYPE=LINECOLOR on the KEYLEGEND statement, so you only get a color swatch of the line color. If you remove that option, you should get a legend chiclet that looks more like the series plot. Hope this helps!

Leave A Reply

Back to Top