Closed kassambara closed 7 years ago
Now, a new argument tables.theme
is available in ggsurvplot()
to apply a specific ggplot2 theme to all the tables under the main survival plots.
Fit survival curves
library(survival)
fit <- survfit( Surv(time, status) ~ sex, data = lung )
Default output of ggsurvplot()
library(survminer)
ggsurvplot(fit, data = lung,
risk.table = TRUE,
cumevents = TRUE,
palette = "jco"
)
Clean tables
Example 1:
library(survminer)
ggsurvplot(fit, data = lung,
risk.table = TRUE,
cumevents = TRUE,
palette = "jco",
tables.height = 0.2, # specify tables height
tables.theme = theme_cleantable(), # clean theme for tables
tables.y.text = FALSE # hide tables y axis text
)
Example 2: change the main theme (ggtheme)
library(survminer)
ggsurvplot(fit, data = lung,
risk.table = TRUE,
cumevents = TRUE,
palette = "jco",
tables.height = 0.2, # specify tables height
tables.theme = theme_cleantable(), # theme for tables
tables.y.text = FALSE, # hide tables y axis text
ggtheme = theme_light() # main theme
)
Example 3: use different themes for main plot and tables
library(survminer)
ggsurvplot(fit, data = lung,
risk.table = TRUE,
cumevents = TRUE,
palette = "jco",
tables.height = 0.2, # specify tables height
tables.theme = theme_minimal() + theme_cleantable(), # theme for tables
tables.y.text = FALSE, # hide tables y axis text
ggtheme = theme_gray() # main theme
)
Example 4: Remove axis labels but not tick labels
library(survminer)
ggsurv <- ggsurvplot(fit, data = lung,
risk.table = TRUE,
cumevents = TRUE,
palette = "jco",
tables.height = 0.2, # specify tables height
tables.y.text = FALSE, # hide tables y axis text
ggtheme = theme_gray() # main theme
)
# Change table axis labels
ggsurv$table <- ggsurv$table + labs(x = NULL, y = NULL) # risk table
ggsurv$cumevents <- ggsurv$cumevents + labs(x = NULL, y = NULL) # cumulative events table
ggsurv # print
(e-mail from a user)
The at risk table has a label below it, which duplicates the label on the graph itself. To my eyeball the duplication is undesirable. Is there a way to get rid of it?