6 Efficacy figure
Following the ICH E3 guidance, primary and secondary efficacy endpoints need to be summarized in Section 11.4, Efficacy Results and Tabulations of Individual Participant.
library(haven) # Read SAS data
library(dplyr) # Manipulate data
library(r2rtf) # Reporting in RTF format
library(survival) # Fit survival model
In this chapter, we illustrate how to create a simplified KaplanMeier plot in a study. For the survival analysis in efficacy, time to dermatologic event (TTDE) will be analyzed.
R packages such as visR and survminer can create more informative KaplanMeier plots. Interested readers can find examples on their websites.
6.1 Analysis dataset
To prepare the analysis, the adtte
dataset is required.
adtte < read_sas("dataadam/adtte.sas7bdat")
First, to prepare the analysis ready data,
filter all records for the efficacy endpoint of time to event of interest (TTDE
)
using PARAMCD
(or PARAM
, PRAMN
), then select the survival analysis related variables:

TRTP
: treatment arm (using corresponding numeric codeTRTAN
to reorder the levels, “Placebo” will be the reference level) 
AVAL
: timetoevent analysis value 
CNSR
: event (censoring) status
6.2 Create KaplanMeier curve
The survival
package is used to obtain the KM estimate.
# Fit survival model, convert the time value from Days to Month
fit < survfit(Surv(AVAL_m, 1  CNSR) ~ TRTP, data = adtte_ttde)
We save the simplified KM plot into a .png
file using code below.
# Save as a PNG file
png(
file = "tlf/fig_km.png",
width = 3000,
height = 2000,
res = 300
)
plot(
fit,
xlab = "Time in Months",
ylab = "Survival probability",
mark.time = TRUE,
lwd = 2,
col = c(2, 3, 4),
lty = c(1, 2, 3)
)
dev.off()
Now, we can use the r2rtf
package to create a formatted RTF figure.
More details can be found on the r2rtf website.
# Create RTF figure
rtf_read_figure("tlf/fig_km.png") %>% # Read the PNG file from the file path
rtf_title(
"KaplanMeier Plot for Time to First Dermatologic Event by Treatment Group",
"All Participants"
) %>% # Add title or subtitle
rtf_footnote("footnote") %>% # Add footnote
rtf_source("[datasource: adamadtte]") %>% # Add data source
rtf_figure(fig_width = 6, fig_height = 4) %>% # Set proportional figure size to the original PNG figure size
rtf_encode(doc_type = "figure") %>% # Encode figure as rtf
write_rtf(file = "tlf/tlf_km.rtf")