Get startedGet started for free

Understanding and visualizing Kaplan-Meier curves

1. Understanding and visualizing Kaplan-Meier curves

In this video, we will learn more about how to visualize Kaplan-Meier curves. Much of what you will learn in this video will also apply for other methods that we will look into in the upcoming videos. Being able to visualize survival curves means being able to communicate your results without much mathematical vocabulary. And what is statistics without being able to communicate the results?

2. The ggsurvplot function

Although the survival package comes with plotting functionality I would like to focus on the ggsurvplot function from the survminer package. This function can take a Kaplan-Meier estimate as an input. The fit argument takes the survfit object. A minimal version of a ggsurvplot example is just entering the survfit object into the ggsurvplot function and you are done. But if you want to change your visualization a little, you can. The most important arguments and their default values are shown here. Palette can be used to define the colors of the curves. By default, it uses the default color palette of ggplot, which is usually already good. Linetype can be used to define the linetype of the curves. Surv-dot-median-dot-line allows you to indicate if you want to highlight the median survival time. Risk-dot-table allows you to show a table with the number of subjects at risk of dying. Cumevents allows you to show a table with the number of events that happened already. Cumcensor allows you to show a table with the number of censored observations so far. Tables-dot-height can be used to indicate how big the tables should be. Let's look at an example!

3. The ggsurvplot function

You already computed the Kaplan-Meier estimate for the GBSG2 data set. Now let's visualize your result. We enter the Kaplan-Meier estimate which we called km for the fit argument. We want the line to be blue for which we use the palette argument and we want the line to be solid for which we use linetype = 1. To add the median to our plot we add surv-dot-median-dot-line = "hv". "hv" stands for horizontal and vertical, which leads to a horizontal and a vertical line in the plot. We would like to see all three tables and want them reasonably small, so tables-dot-height is 0-point-1. Feel free to pause the video now and study the arguments and their values. You will need this for the upcoming exercise.

4. The survfit function

Let's revisit the survfit function. Why? Because you don't yet know everything about the survfit function. What you do know is that the survfit function computes the Kaplan-Meier curve when you enter a formula, as you did in one of the exercises. But the survfit function is actually not specific to Kaplan-Meier. It is actually a function that returns a survival curve. So, instead of entering a formula we could enter a Cox model object and it would return the survival curve or curves for the Cox model. What's a Cox model? Stay tuned for the next videos!

5. Let's practice!

Now it's your turn.