mk_forestplot: Create a function for making publishable ggplot2 forest plot.

View source: R/mk_forestplot.R

mk_forestplotR Documentation

Create a function for making publishable ggplot2 forest plot.

Description

mk_forestplot takes a data frame as input and returns a function for making forest plots that can display estimates and their confidence intervals of different groups and subgroups. Forest plots make it easy to compare between groups.

Usage

mk_forestplot(df)

Arguments

df

A data frame where each row represents a group, subgroup or model and etc. For example, say you trained 10 simple linear regressions, each using a different feature, and collected the coefficient estimates and their 95% confidence intervals into a data frame. You want to see the difference between these coefficient estimates. You can call mk_forestplot on this data frame of coefficient estimates and 95% confidence intervals.

Value

function(xvar, xmin_var, xmax_var, yvar, colorby = '1', panel_space = 1, strip_text_y_margin=c(2, 3, 2, 3), plot_margin=c(2, 1, 2, 1), font_size=14)

  • xvar. String, name of a continuous var of estimates or effect sizes.

  • xmin_var. String, name of a continuous var of the lower bounds of those estimates, for example, 95% lower bound.

  • xmax_var. String, name of continuous var of the upper bounds of those estimates, for example, 95% upper bound.

  • yvar. String, name of a categorical var for the left y-axis. Each value should corresponds to one row from the data. The data should not contain repeated rows.

  • colorby. String, name of a categorical variable for faceting and all line segments within the same facet will have the same color. Default = "1", meaning no such variable is supplied.

  • panel_space. Number, space between the facets. Default = 1.

  • add_vline_xpos. Number, the x position (default = 0) where to draw a vertical dashed line.

  • strip_text_y_margin. Vector of 4 numbers, sets the position of the facet panel text relative to the boundry of strips of facet panels. Default = c(2, 3, 2, 3), going from top, right, bottom, to left.

  • plot_margin. Vector of 4 numbers, sets the position of the plot relative to canvas. Default = c(2, 1, 2, 1), going from top, right, bottom, to left.

  • font_size. Overall font size. Default = 14. The font size of the axes and legend text is a fraction of this value.

  • xlab. A string for labeling the x-axis. When NULL (default), the value of xvar is used. This parameter is added to the function because the object returned from the function cannot be modified by add_labs().

  • title. A string as the title of the plot. When NULL (default), the plot is untitled. This parameter is added to the function because the object returned from the function cannot be modified by add_labs().

  • scale_x_pct. Logical. If TRUE, use the x-labels are all

  • digits. Number of digits when using percent format on x-axis.

Examples

inst/examples/ex-mk_forestplot.R

gmlang/ezplot documentation built on Sept. 18, 2022, 6:33 a.m.