Clinical Graphs: Spider plot

19

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 helped 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:\spider.sas';
  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';
run;

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

Share

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.

19 Comments

    • 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;

  2. Hi Sanjay, what are the changes that needs to be done in the code above so it will work in SAS 9.3?

    Thanks!

    • 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.

  3. 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?

  4. 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.
    Reza

  5. 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.

    raj

    • 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!

  6. Hi Sanjay,

    Thank you very much for these great tips and support in generating very useful graph. I have one question around this spider plot and was wondering if you could help. Considering the example data in this spider plot, lets say there is one patient who have partial response at first two time point and at the third timepoint the patient has complete response. Lets consider the second yellow line in the plot. So if that patient has complete response at the third timepoint after partial response at first 2 timepoints, how could we make the line colour and circle change according to the response from second timepoint to third timepoint?

    Is this something that can be done with this existing example code?

    Many thanks for looking into this and for your time.

    Thanks.
    Rafi

    • Dan Heath

      The existing template should work fine, but you will need to do a little data manipulation to get just what you want. When a subject changes response state, you will need to create two data records: the first using the PREVIOUS response group value and then a duplicate record using the CURRENT response group value. The series plot will then appear to transition to the new response. If you sort the data, make sure you sort it by the X variable. Let me know if this works for you.

      • Thank you very much Dan for your swift response! I applied the solution but it seems just the circle colour changes, not the line connecting from previous timepoint. I tried to update the last patient data from the example code to be like this -

        103205 0 0.0 . Partial Response
        103205 8 -0.4 . Partial Response
        103205 16 -0.5 . Partial Response
        103205 24 -0.55 . Partial Response
        103205 32 -0.55 . Partial Response
        103205 40 -0.65 . Partial Response * Duplicated previous response;
        103205 40 -0.65 . Complete Response * Current response;
        103205 48 -0.70 . Partial Response
        103205 58 -0.80 58 Partial Response Ongoing

        Perhaps I am doing not exactly as you mentioned?

        Thanks.
        Rafi

        • Dan Heath

          This response change needs to happen for both the "rgroup" and "TGroup" variables so that both the series and the scatter are affected.

          • Dan Heath

            For the record, one other required change was to make sure that the GROUP variable on the SERIES plot is unique every time the GROUPLC and GROUPMC value changes for a subject. The reason is that the line color for a given GROUP value will not change once the line is started. To do this, create another column that combines attributes such as subject and response into one string value and use that for the GROUP instead of the subject variable.

Back to Top