SingleTable.plot: Plot Method for 'singletable' objects.

View source: R/SingleTable-methods-exported.R

SingleTable.plotR Documentation

Plot Method for singletable objects.

Description

Produces various plots for single table analysis.

Usage

SingleTable.plot(
  single_table_Obj,
  type = "side_by_side",
  xlim = NULL,
  add_vertical = NULL,
  by = "line_type"
)

Arguments

single_table_Obj

The object inheriting from class singletable.

type

a character string specifying the type of plots to produce. Options are sidebyside(default) and overlay.

xlim

a numeric value specifying the lower and upper limits of the x-axis. Default is NULL.

add_vertical

a numeric value specifying the x-value for a vertical reference line at x=addline. Default is NULL.

by

a character string specifying the way to distinguish different plots. Options are line_type(default) and color.

Details

If type="sidebyside", the posterior distribution of measure and the prior distribution are drawn side by side in two plots. If type="overlay", the posterior distribution of measure and the prior distribution are overlaid in one plot.

Value

A ggplot2 object is returned.

Examples

## Assume we have a 2x2 table:{{40,56},{49,60}} and set prior parameters as a1=b1=a2=b2=rho=0.5.
 
 library(mmeta)
 library(ggplot2)
 ## If exact method is used, the codes for sampling method are similar.
 ## Create object \code{single_table_obj_exact}
 single_table_obj_exact <- SingleTable.create(a1=0.5,b1=0.5,
 a2=0.5,b2=0.5,rho=0.5, y1=40, n1=96, y2=49, n2=109,model="Sarmanov",measure="OR")
 ## model fit
 single_table_obj_exact <- SingleTable.modelFit(single_table_obj_exact, method = 'exact')
 ## Summary of the fitting process (default)
 single_table_obj_exact <- SingleTable.summary(single_table_obj_exact, alpha = 0.05)
 ## Plot the densities side-by-side
 SingleTable.plot(single_table_obj_exact, type = 'side_by_side')
 ## set xlim between 0 to 4 and add vertical line at x = 1
 SingleTable.plot(single_table_obj_exact, type = 'side_by_side',
 xlim = c(0,4), add_vertical = 1)
 ## override xlab and add title via ggplot2
 plot_obj <- SingleTable.plot(single_table_obj_exact, type = 'side_by_side',
 xlim = c(0,4), add_vertical = 1)
 plot_obj + xlab('Odds ratio') + ggtitle("Plot of density function")
 ## Overlay plot the density
 SingleTable.plot(single_table_obj_exact, type = 'overlay')
 ## Plot by color instead of line type
 SingleTable.plot(single_table_obj_exact, type = 'overlay',by = 'color')
 

mmeta documentation built on Feb. 16, 2023, 8:39 p.m.