rlogistic-regressionr-forestplot

how to update text in forest plots produced by forestmodel function in R?


I am creating a forest plot for logistic regression model.

The forest plot produced has the word "p" for the p-values column. I want to change it from "p" to "p-value".

Here is my code:

library(forestmodel)

p1 <- forest_model(logisticR, )

p1

enter image description here


Solution

  • As per the help page of the forest_model() function for the forestmodel package, you'll need to create a custom panel set to change anything like the header of the output. Your code is not reproducible (in fact, it would lead to an error as is), so I'm using the example provided in the function's help page to provide a solution:

    library(forestmodel)
    
    panels <- list(forest_panel(width = 0.03), 
                   forest_panel(width = 0.1, display = variable, fontface = "bold", heading = "Variable"), 
                   forest_panel(width = 0.1, display = level), 
                   forest_panel(width = 0.05, display = n, hjust = 1, heading = "N"), 
                   forest_panel(width = 0.03, item = "vline", hjust = 0.5), 
                   forest_panel(width = 0.55, item = "forest", hjust = 0.5, heading = "Odds ratio", linetype = "dashed", line_x = 0), 
                   forest_panel(width = 0.03, item = "vline", hjust = 0.5), 
                   forest_panel(width = 0.12, display = if_else(reference, "Reference", sprintf("%0.2f (%0.2f, %0.2f)", trans(estimate), trans(conf.low), trans(conf.high))), display_na = NA), 
    #### SEE BELOW FOR HEADER CHANGE TO P-VALUE
                   forest_panel(width = 0.05, display = if_else(reference, "", format.pval(p.value, digits = 1, eps = 0.001)), display_na = NA, hjust = 1, heading = "p-value"), 
    ####
                   forest_panel(width = 0.03))
    
    library("survival")
    library("dplyr")
    pretty_lung <- lung %>%
      transmute(time,
                status,
                Age = age,
                Sex = factor(sex, labels = c("Male", "Female")),
                ECOG = factor(lung$ph.ecog),
                `Meal Cal` = meal.cal
      )
    
    forest_model(coxph(Surv(time, status) ~ ., pretty_lung), panels)
    

    enter image description here