Skip to content
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

ggforest please add optional printed variable names #405

Open
PeterStrom opened this issue Jul 7, 2019 · 8 comments
Open

ggforest please add optional printed variable names #405

PeterStrom opened this issue Jul 7, 2019 · 8 comments

Comments

@PeterStrom
Copy link

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.

@helenajr
Copy link

I agree!

@kremerkm
Copy link

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.

@corneliushennch
Copy link

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:

NikNakk/forestmodel#24 (comment)

@rganly
Copy link

rganly commented Jun 22, 2021

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.

@corneliushennch
Copy link

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.

@GiorgiaCaruana
Copy link

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

@txhays
Copy link

txhays commented Jun 17, 2022

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.

@arielhasidim
Copy link

arielhasidim commented Mar 7, 2023

+1

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants