I am trying to plot a cox proportional hazard ratio model calculated with survival's coxph() using forestmodel's forest_model function.
The covariates are factors, some of their name have a space in them ie. "Surgical Resection". When I enter these into the coxph model I refer to them with backticks so that R know to ignore the space:
res.coxm <- coxph(Surv(Survival_Overall, Death == 1) ~ Age+`Surgical Resection`
+`Intracranial BoD`+`Systemic BoD`+`Treatment prior to CNS involvement`+
`Systemic treatment after CNS involvlement`+`Brain-directed radiotherapy`, data = df)
The model runs fine. When I try to plot this model, I get an error:
forest_model(res.coxm, format_options = list(color="black", text_size=4.5))
Error in grouped_df_impl(data, unname(vars), drop) : Column `Surgical Resection` is unknown
Has anyone faced this issue?
The plot forms fine if: - I change the variable names to their "spaceless" versions, i.e. "surgical_resection" instead of "Surgical Resection" OR - If I change the variables from factors to integers, but keep the names with the spaces
I've tried to recode my original df with a variety of different column naming functions incl names(sd)
Any ideas? Thanks!!