survminer
survminer copied to clipboard
ggforest please add optional printed variable names
Would be very nice to have an argument for printing different variable names than what is in the columns of the data.frame. E.g.
ggforest(... , printNames=c(age="Age at birth", country="Country at birth"))
That would make the plot ready for publication. Even if it is possible to name variables in a data.frame "Age at birth", it is very cumbersome to work with.
I agree!
I also would like this function. I haven't even been able to find a work around but admittedly i'm kind of new to R and coding of functions.
Or how about implementing the use of labelled variables using the labelled
package. forestmodel
can do this for other models, but coxph doesn't work properly at the moment, as I elaborated on here:
https://github.com/NikNakk/forestmodel/issues/24#issuecomment-825150537
This would be an extremely useful option; otherwise the plots are messy and cannot be shared for presentations or publishing. There is also no option to omit certain covariates from the ggforest plot.
The best solution I found so far was the finalfit
package. Its hr_plot function makes really nice hr_plots and it's quite easy to customize since it's also based on ggplot. I really like the whole package for clinical/survival analyses as it is super easy to use if you are familiar with the tidyverse
packages and its philosophy.
Hello! Just re-opening the topic, do you know if the bug on labels has somehow been fixed on ggforest? The graph is otherwise perfect but I don't know how to fix it for publication...
Hi, I was struggling with this too. Just came up with a messy work around. I made custom panels and manually wrote each row.
res.cox <- coxph(Surv(time, status) ~ Positive_ES + Sex + Race + CAKUT + Laterality, CAKUTSurv)
panels <- list(
list(width = 0.03),
list(width = 0.1, display = c("Genetic Disorder","","Sex","","Race","","","","CAKUT","","","","","","","Laterality",""),
fontface = "bold", heading = "Variable"),
list(width = 0.1, display = ~level),
list(width = 0.05, display = ~n, hjust = 1, heading = "N"),
list(width = 0.03, item = "vline", hjust = 0.5),
list(width = 0.55, item = "forest", hjust = 0.5, heading = "Hazard ratio", linetype = "dashed",
line_x = 0),
list(width = 0.03, item = "vline", hjust = 0.5),
list(width = 0.12, display = ~ ifelse(reference, "Reference", sprintf(
"%0.2f (%0.2f, %0.2f)",
trans(estimate), trans(conf.low), trans(conf.high)
)), display_na = NA),
list(
width = 0.05,
display = ~ ifelse(reference, "", format.pval(p.value, digits = 1, eps = 1e-5)),
display_na = NA, hjust = 1, heading = "P-value"
),
list(width = 0.03)
)
forest_model(res.cox, panels, factor_separate_line = FALSE)
hope this helps.
+1
The issue is mentioned at SO with an alternative package... https://stackoverflow.com/questions/73185232/survminer-ggforest-how-to-change-variable-names