-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: additional arguments for theme_risktable_default()
#230
Comments
Thanks for the post @jpnolte ! Find responses below. Please note that the defaults were set to meet many needs. But we know that it does not meet everyone's need, which is why we try to make it possible modify the defaults.
|
Thank you so much for the quick response. You are absolutely right, (2) and (3) can be achieved by providing the arguments through survfit2(Surv(time, status) ~ sex, data = df_lung) |>
ggsurvfit() +
scale_x_continuous(expand = c(0.005, 0),
breaks = seq(0, 34, 2),
limits = c(0, 34)) +
scale_y_continuous(expand = c(0, 0.05),
breaks = seq(0, 1, 0.25),
labels = scales::label_percent()) +
add_risktable(
risktable_stats = "n.risk",
theme = list(
theme_risktable_default(),
theme(
axis.text.y = element_text(hjust = 0, margin = margin(r = 10)),
plot.caption = element_text(hjust = 0),
plot.title.position = "plot"
)
)
) ad 1) Yes, this is exactly my point. I think, and I know others that agree, it looks better the less empty space there is between the actual start of the y and x axis and the first break. In the example above I reduced the empty space causing the overlap. I was thinking that the ad 4) I already tried to provide the survfit2(Surv(time, status) ~ sex, data = df_lung) |>
ggsurvfit() +
scale_x_continuous(expand = c(0.04, 0),
breaks = seq(0, 34, 2),
limits = c(0, 34)) +
scale_y_continuous(expand = c(0, 0.05),
breaks = seq(0, 1, 0.25),
labels = scales::label_percent()) +
add_risktable(
risktable_stats = "n.risk",
theme = list(
theme_risktable_default(),
theme(
axis.text.y = element_text(hjust = 0, margin = margin(r = 5)),
plot.caption = element_text(hjust = 0),
plot.title.position = "plot"
)
),
hjust = 1
) If you would then also right align the axis text on the x axis you can see how survfit2(Surv(time, status) ~ sex, data = df_lung) |>
ggsurvfit() +
scale_x_continuous(expand = c(0.04, 0),
breaks = seq(0, 34, 2),
limits = c(0, 34)) +
scale_y_continuous(expand = c(0, 0.05),
breaks = seq(0, 1, 0.25),
labels = scales::label_percent()) +
add_risktable(
risktable_stats = "n.risk",
theme = list(
theme_risktable_default(),
theme(
axis.text.y = element_text(hjust = 0, margin = margin(r = 5)),
plot.caption = element_text(hjust = 0),
plot.title.position = "plot"
)
),
hjust = 1
) +
theme(axis.text.x = element_text(hjust = 1)) So I think this is also a limitation of |
I think updating an example for the theme argument is a great idea, thanks.
|
Would it be possible to allow the risk table text to extend beyond the plot, i.e. so it isn't clipped, like a coord_cartesian(clip = "off") for the risk table? In this way, large numbers at either end could simply just extend beyond the plot when there is no padding. The user could then manually adjust the risk table axis.text.y accordingly and set the plot.title.position to "plot". |
@ddsjoberg I think an elegant solution could be to design the risk table like in the attached plots. This design allows for large numbers in the risk table without padding as well as long labels for the strata without an undesirable gap between the plot's y-axis and y-axis title. Would it be possible to align the plot and risk table in that way? |
I don't disagree! I don't know exactly how to make that happen. Essentially, we need to assign different padding to the risktable "figures" (they are just ggplots here), while still ensuring the primary figure lines up with the risktables. What we're doing internally that during the print of these objects, we inspect the primary plots and make modificatons to the risktable plot(s) to ensure the line up with one another. This allows the users to modify the primary plot in any way they'd like and the risktable still lines up (a great feature!). I don't know how we could ensure the alignment while still giving the users the flexibility they also want. It's probably possible, but to be up front, I don't have the bandwidth to investigate this at the moment (or the foreseeable future), sadly. It's unfortunate, because this would be a great feature (and there are a bunch of other things I want to improve in the package as well). |
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:
(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 theexpand
argument inscale_x_continouus()
(e.g.,scale_x_continuous(expand = c(0.015, 0))
) or play with thewidth
argument when saving withggsave()
until the text does not overlap anymore.But what if you would include an argument called
margin
withintheme_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 (
hjust
oralign
) 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_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 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 thehjust
argument 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
expand
toc(0, 0)
so the axes would start at the same spot. The other suggestions would be the icing on the cake.The text was updated successfully, but these errors were encountered: