First of all, thank you so much for the amazing work. Your package is so much better than the survminer package I used before. I've done a few projects now with your package and some details in adapting the risk table would be a great addition.
Lets take this a small reprex:
p <- survfit2(Surv(time, status) ~ sex, data = df_lung) |>
ggsurvfit() +
add_risktable(risktable_stats = "n.risk") +
scale_ggsurvfit()
(1) When dealing with larger patient numbers (e.g., everything above 1000) it will usually lead to the numbers at timepoint 0 overlap with the axis text on the y axis of the risk table. In the add_risktable() documentation you can see it in example 3. So my solution up until now is to either increase the expand argument in scale_x_continouus() (e.g., scale_x_continuous(expand = c(0.015, 0))) or play with the width argument when saving with ggsave() until the text does not overlap anymore.
But what if you would include an argument called margin within theme_risktable_default() which would work like the following but for the risktable and not the plot.
p + theme(axis.text.y = element_text(margin = margin(r = 10)))
(2) Left align the axis text of the y-axis of the risk table. This is more of a subjective option, but if you are already thinking about creating the first (important) one, it might be fast to also integrate this as an additional argument (hjust or align) to theme_risktable_default(). Here is how to do it for the plot. Would be nice to have it for the risk table as well.
p + theme(axis.text.y = element_text(hjust = 0))
(3) Positioning the stats_label above the axis text of the y-axis in the risk table instead of on top of the table itself. I didn't have time yet to look up your way of defining the stats_label (e.g., At risk), but it looks like you use ggtitle(). If so, this might also be quite easy to integrate and useful since some other programs seem to support it.
p +
ggtitle("Testing this") +
theme(
plot.caption = element_text(hjust = 0),
plot.title.position = "plot"
)
(4) Right align text (the numbers) from geom_text() in the risk table. I know this is only a matter of appearence, but it gets way easier to read and compare larger numbers with smaller ones. This one I did not figure out yet, since providing geom_text() through add_risktable() with the hjust argument for some reason puts a small offset there additionally.
survfit2(Surv(time, status) ~ sex, data = df_lung) |>
ggsurvfit() +
add_risktable(risktable_stats = "n.risk", hjust = "right")
I would really appreaciate if you could add the first suggestion, since this is rather annoying. Also it would allow me to set expand to c(0, 0) so the axes would start at the same spot. The other suggestions would be the icing on the cake.
First of all, thank you so much for the amazing work. Your package is so much better than the
survminerpackage I used before. I've done a few projects now with your package and some details in adapting the risk table would be a great addition.Lets take this a small reprex:
(1) When dealing with larger patient numbers (e.g., everything above 1000) it will usually lead to the numbers at timepoint 0 overlap with the axis text on the y axis of the risk table. In the
add_risktable()documentation you can see it in example 3. So my solution up until now is to either increase theexpandargument inscale_x_continouus()(e.g.,scale_x_continuous(expand = c(0.015, 0))) or play with thewidthargument when saving withggsave()until the text does not overlap anymore.But what if you would include an argument called
marginwithintheme_risktable_default()which would work like the following but for the risktable and not the plot.(2) Left align the axis text of the y-axis of the risk table. This is more of a subjective option, but if you are already thinking about creating the first (important) one, it might be fast to also integrate this as an additional argument (
hjustoralign) totheme_risktable_default(). Here is how to do it for the plot. Would be nice to have it for the risk table as well.(3) Positioning the
stats_labelabove the axis text of the y-axis in the risk table instead of on top of the table itself. I didn't have time yet to look up your way of defining thestats_label(e.g., At risk), but it looks like you useggtitle(). If so, this might also be quite easy to integrate and useful since some other programs seem to support it.(4) Right align text (the numbers) from
geom_text()in the risk table. I know this is only a matter of appearence, but it gets way easier to read and compare larger numbers with smaller ones. This one I did not figure out yet, since providinggeom_text()throughadd_risktable()with thehjustargument for some reason puts a small offset there additionally.I would really appreaciate if you could add the first suggestion, since this is rather annoying. Also it would allow me to set
expandtoc(0, 0)so the axes would start at the same spot. The other suggestions would be the icing on the cake.