Remove dash on strata line when using ggsurvplot and survminer

519 Views Asked by At

How do I change the line type for the sex strata so that it is a line without all the small "crosses" as shows in the picture below? I hope to get just a solid line instead. The cross makes things look a little congested when there is a lot of data points.

library(survminer)


fit <- survfit( Surv(time, status) ~ sex, data = colon )
ggsurvplot(fit, colon,
                palette = "jco", pval = TRUE)

enter image description here

3

There are 3 best solutions below

0
On BEST ANSWER

You just have to set censor=FALSE.

library(survminer)
library(survival) # to obtain the colon dataset

fit <- survfit(Surv(time, status) ~ sex, data = colon)
ggsurvplot(fit, colon, censor = FALSE,
           palette = "jco", pval = TRUE)

survival_plot

If you search the help of ggsurvplot, you will find there are more parameters to customize the censored events:

Censor points

  • censor: logical value. If TRUE (default), censors will be drawn.

  • censor.shape: character or numeric value specifying the point shape of censors. Default value is "+" (3), a sensible choice is "|" (124).

  • censor.size: numeric value specifying the point size of censors. Default is 4.5.

0
On

These are censoring events and it is normally expected that you show them on a survival curve. If you really want to get rid of them (and I don't see an option to do this directly within ggsurvplot), you can remove the layer they are in after the plot is created. Here's a reprex:

library(survminer)
library(survival)

fit <- survfit( Surv(time, status) ~ sex, data = colon )
g <- ggsurvplot(fit, colon, palette = "jco", pval = TRUE)

g$plot$layers[[3]] <- NULL

g

Created on 2022-12-15 with reprex v2.0.2

4
On

You could use the argument censor.shape with NA like this:

library(survminer)
library(survival)
fit <- survfit( Surv(time, status) ~ sex, data = colon )
ggsurvplot(fit, colon,
           palette = "jco", pval = TRUE,
           censor.shape=NA)

Created on 2022-12-15 with reprex v2.0.2


Check this answer with some useful links.

For more information and options check the Censor points part in the documenation