geek45
geek45

Reputation: 723

ggsurvplot - adjust thickness of strata indicators

Is it possible to adjust the thickness of the strata indicators?
The indicators in the legend are not as thick as in the risk.table.

library(survminer)
library(survival)

fit <- survfit(Surv(time, status) ~ sex, data = lung)

p <- ggsurvplot(
  fit,
  size = 1,
  legend.labs = c("A", "B"),
  linetype = "solid",
  break.time.by = 365,
  palette = c("#E7B800", "#2E9FDF"),
  risk.table = TRUE,
  censor = FALSE,
  risk.table.title = "No. at risk",
  tables.y.text = FALSE,
  legend.title = "",
  tables.theme = theme_cleantable() +
    theme(plot.title = element_text(size = 20))
)
p

The red arrow indicates the discrepancies in line thickness.

enter image description here

I tried to adjust but I am not aware how to find out which argument is related to the indicators. If there is one at all.

  tables.theme = theme_cleantable() +
    theme(plot.title = element_text(size = 20),
          strata.line.x = element_line(size = 5.5))

Upvotes: 1

Views: 55

Answers (1)

Edward
Edward

Reputation: 18543

The text that appears in the risk table on the y-axis (tables.y.text) is TRUE by default. If you change this to FALSE, you'll get a thick line instead. This is achieved internally using element_markdown from the ggtext package. The actual function is .set_large_dash_as_ytext.

I agree that it is thicker than it should be. However, you can change it to use a thinner dash with the unicode value for a small em dash (\ufe58):

p$table <- p$table + 
  scale_y_discrete(labels=rep("\ufe58", 2)) +
  theme(plot.margin = margin(0, 0, 0, 0, "cm")); p

enter image description here


link to list of unicode values

Upvotes: 1

Related Questions