plot.summary.rms {ormPlot}R Documentation

Forest Plot of an rms model summary

Description

Convenience function to create a plot of the orm model summary. For further customizing the plots use return_ggplots = TRUE This will create 2 ggplot2 objects that can be joined with the join_ggplots commands.

Usage

## S3 method for class 'summary.rms'
plot(x, ...)

forestplot(
  x,
  return_ggplots = FALSE,
  plot.widths = c(0.5, 0.5),
  title = "Odds ratio",
  digits = 3,
  shape = 19,
  header = NULL,
  limits = NULL,
  breaks = c(0.5, 1, 1.5, 2, 3, 4),
  theme = ggplot2::theme_get(),
  row.names.y = NULL
)

forestplot.default(x, ...)

forestplot.summary.rms(x, ...)

Arguments

x

result of a summary command on orm or lrm model ie a summary.rms class object

...

see parameters of method forestplot

return_ggplots

if TRUE the function returns 2 ggplot objects in a list instead of drawing a tablegrid

plot.widths

the relative widths of the left and right plot should be a vector (c()) with 2 elements that sum to 1 defaults to equal widths

title

the tile row of the drawn plot

digits

the number of significant digits to display

shape

point shape, see aes_linetype_size_shape

header

names of the table columns

limits

the x axis limits as a vector, see also: scale_continuous

breaks

the x axis breaks as a vector,help see also: scale_continuous

theme

the desired ggplot2 theme

row.names.y

new names for the variable rows

Examples

set.seed(123)
#load the libraries
library(rms)
library(ormPlot)
library(ggplot2)

#make the datadist
dd<-rms::datadist(educ_data)
options(datadist="dd")

#create the model
cran_model <- orm(educ_3 ~ YOBc + sex + height_rzs + n_siblings  + cran_rzs, data = educ_data)

#the antilog true produces odd ratios (default value for orm and lrm)
s<-summary(cran_model, antilog = TRUE)

#set the plotting default theme (optional)
theme_set(theme_classic())

#show simply the result
forestplot(s)

#return modifiable ggplots
forestplot(s, return_ggplots = TRUE )

#new row names and header
newnames <- c("Year of birth", "Height", "Number of children", "Cranial volume", "Sex" )
newhead <- c("Odds Ratio", "CI 5%", "CI 95%" )

#adjust also the relative plot widths and change the color and shape
newtheme <- theme_classic() + theme(text = element_text(color = "red", size = 12),
                                    line = element_line(color= "red"),
                                    rect = element_rect(color="red"))

forestplot(s, row.names.y = newnames, header = newhead,
           plot.widths = c(0.6,0.4), shape = 17,
           theme = newtheme)

[Package ormPlot version 0.3.6 Index]