user1700890
user1700890

Reputation: 7730

Adding title to ggsurvplot

I would like to add title to ggsurvplot. Here is my code:

library(survival)
library(survminer)

fit <- survfit(Surv(time, status) ~ sex, data = lung)
ggsurvplot(fit, data =lung, main = "This is title")

It generates plot, but without title. If add risk.table = TRUE, then I get title on top of risk table, but not the main plot.

library(survival)
library(survminer)

fit <- survfit(Surv(time, status) ~ sex, data = lung)
ggsurvplot(fit, data =lung, main = "This is title", 
           risk.table = TRUE)

ggsurvplot title

Any idea how to fix it?

Upvotes: 3

Views: 15059

Answers (2)

&#214;mer An
&#214;mer An

Reputation: 664

And if you want to center the title and change the font type as bold and/or make other changes to the ggplot theme, use + theme():

ggtheme = theme_minimal() + theme(plot.title = element_text(hjust = 0.5, face = "bold"))

Upvotes: 4

j.Rinehart
j.Rinehart

Reputation: 288

Call the title with title = , not with main =.

ggsurvplot(fit, data =lung, title = "This is title", 
           risk.table = TRUE)

Output_Link_Here as I guess I'm too new to embed

Upvotes: 6

Related Questions