We build the following dataset:
# Library
library(tidyverse)
# 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))
data
format :
A data frame
with 45 observations on the following 5 variables :
ID
: ID of each participant patient, which will be used as a unique
identifier
sum
: The variable you want to plot, and it
must be a numeric variable
RECIST
: This variable is a
group identifier (the color of the plot)
lesion
: The
variable to annotate particular patients, and it must be binary
week
: The time of each visit, which can be measured by
day, month, and year
ID | sum | RECIST | lesion | week | changebsl |
---|---|---|---|---|---|
1 | 45 | PD | 0 | 0 | 0.000000 |
1 | 56 | PD | 0 | 9 | 24.444444 |
2 | 28 | PD | 1 | 0 | 0.000000 |
2 | 28 | PD | 1 | 9 | 0.000000 |
3 | 79 | PD | 1 | 0 | 0.000000 |
3 | 72 | PD | 1 | 9 | -8.860760 |
3 | 67 | PD | 1 | 18 | -15.189873 |
3 | 75 | PD | 1 | 27 | -5.063291 |
For this spider plot, we will use the package ggplot2
and its functions.
This document is a work of the statistics team in the Biostatistics and Medical Information Department at Saint-Louis Hospital in Paris (SBIM).
Based on The R Graph Gallery by Yan Holtz.