Spider Plot
Indicator variable


We will here use the ggplot2 package and the dataset created in the Data & Functions page.

# Libraries
library(tidyverse)
library(ggplot2)

# Creation of dataset
data <- data.frame(
  c(1,1,2,2,3,3,3,3,3,3,3,3,3,3,3,3,5,5,6,6,7,7,15,15,17,17,19,19,20,20,21,21,21,22,22,24,24,25,25,25,25,25,25,25,25),
  c(45,56,28,28,79,72,67,75,77,77,75,71,74,74,71,72,69,79,27,28,15,21,43,43,27,32,32.6,38,131,142,27,26,31,90,109,83,71,166,45,46,46,44,46,48,47),
  c("PD","PD","PD","PD","PD","PD","PD","PD","PD","PD","PD","PD","PD","PD","PD","PD","PD","PD","SD","SD","PD","PD","PD","PD","SD","SD","SD","SD","PD","PD","SD","SD","SD","PD","PD","PD","PD","PR","PR","PR","PR","PR","PR","PR","PR"),
  c(0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0),
  c(0,9,0,9,0,9,18,27,36,45,54,63,72,81,90,99,0,9,0,9,0,9,0,9,0,9,0,9,0,9,0,9,18,0,9,0,9,0,9,18,27,36,45,54,63)
)
colnames(data) <- c("ID","sum","RECIST","lesion","week") 

# add change from baseline variable
data1 <- data %>%
  group_by(ID) %>%
  arrange(ID, week) %>%
  mutate(changebsl = 100*(sum - first(sum))/(first(sum)))  %>%
  ungroup() %>%
  mutate(changebsl = replace(changebsl, changebsl == "NaN", 0)) 
spider_plot <- ggplot(data1) +
    #build the basic graph
    geom_point(aes(x=week, y=changebsl, group=ID, colour=RECIST)) +
    geom_line(aes(x=week, y=changebsl, group=ID, colour=RECIST)) +
    #color
    scale_color_manual(values=c("#1d4f91", "#FF9800", "#228848", '#AE2573', '#D14124')) +
    #axis and title
    labs(x = "Time",
         y = "Change from Baseline (%)",
         title = "Spider Plot",
         shape = " ",
         color = " ") +
    theme_minimal()+
    theme_bw()+
    #font size and background
    guides(fill=guide_legend(title=" "))+
    theme(panel.grid.minor = element_blank(),
          panel.grid.major = element_blank(),
          panel.background = element_blank(),
          plot.title = element_text(hjust = 0.5, size = 16),
          axis.text=element_text(size=16),
          axis.title=element_text(size=16),
          legend.text = element_text(size=16))

# Add Indicator Variable
data1$lesion <- as.factor(data1$lesion)
spider_plot +
  geom_point(data=data1, aes(x=week, y=changebsl, shape=lesion), size = 3) +
      scale_shape_manual(values=c("1" = 8, "0" = NA), labels = c("1" = paste("Indicator", "\n", "Variable"), "0" = " "))




Contact

This document is a work of the statistics team in the Biostatistics and Medical Information Department at Saint-Louis Hospital in Paris (SBIM).
Developed and updated by Noémie Bigot and Anouk Walter-Petrich
noemie.bigot@aphp.fr; anouk.walter-petrich@u-paris.fr

Based on The R Graph Gallery by Yan Holtz.

SBIM