survminer icon indicating copy to clipboard operation
survminer copied to clipboard

ggforest please add optional printed variable names

Open PeterStrom opened this issue 5 years ago • 8 comments

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.

PeterStrom avatar Jul 07 '19 10:07 PeterStrom

I agree!

helenajr avatar Jun 17 '20 17:06 helenajr

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.

kremerkm avatar Oct 16 '20 16:10 kremerkm

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

corneliushennch avatar Apr 23 '21 08:04 corneliushennch

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.

rganly avatar Jun 22 '21 02:06 rganly

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.

corneliushennch avatar Jun 22 '21 07:06 corneliushennch

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...

GiorgiaCaruana avatar Apr 06 '22 17:04 GiorgiaCaruana

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.

txhays avatar Jun 17 '22 18:06 txhays

+1

The issue is mentioned at SO with an alternative package... https://stackoverflow.com/questions/73185232/survminer-ggforest-how-to-change-variable-names

arielhasidim avatar Mar 07 '23 18:03 arielhasidim