How to change reference category in OR plot?

Hello! I have had trouble changing the reference category for a factor when using the function or_plot from package finalfit.

https://finalfit.org/reference/or_plot.html#examples

I have looked at this example however there is no guidance on how to change the reference category in e.g. sex from female to male or age from <40 years to any other category.

Any suggestions?

Thanks in advance!

Just relevel the factors yourself in the data frame.

library(finalfit)
library(dplyr)
library(ggplot2)

# OR plot
data(colon_s)

# edited version
colon_s_edit <- colon_s %>% 
  mutate(sex.factor = factor(sex.factor, levels = c("Male", "Female"))) %>% 
  mutate(age.factor = factor(age.factor, levels = c("60+ years", "40-59 years", "< 40 years")))


explanatory = c("age.factor", "sex.factor", "obstruct.factor", "perfor.factor")
dependent = "mort_5yr"
colon_s_edit %>%
  or_plot(dependent, explanatory)

You could also use fct_revel() in forcats to do it as well.

Thank you so much! That worked.

Could I please also ask if it is possible in any way to remove the reference category from the OR plot so for example if sex= female is the reference category, have only the OR and the box for sex= male in the plot.

If you type ?or_plot in to the console, you can see the documentation for the function. There is a remove_ref parameter, which by default is set to FALSE.

Using the original data:

colon_s %>%
  or_plot(dependent, explanatory, remove_ref = TRUE)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.