| Title: | Create Plots |
|---|---|
| Description: | Create publication-quality plots for epidemiology. |
| Authors: | Neil Wright [aut, cre] |
| Maintainer: | Neil Wright <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.12.3 |
| Built: | 2026-05-19 09:31:31 UTC |
| Source: | https://github.com/neilstats/ckbplotr |
Make a ggplot into CKB style
ckb_style( xlims = NULL, ylims = NULL, gap = c(0.025, 0.025), ext = c(0, 0), ratio = 1.5, width = NULL, height = NULL, base_size = 11, base_line_size = base_size/22, ink = "black", paper = "white", colour = NULL, axis.title.margin = 1, plot.margin = margin(0.5, 1.5, 0.5, 0.5, "lines"), clip = "on" )ckb_style( xlims = NULL, ylims = NULL, gap = c(0.025, 0.025), ext = c(0, 0), ratio = 1.5, width = NULL, height = NULL, base_size = 11, base_line_size = base_size/22, ink = "black", paper = "white", colour = NULL, axis.title.margin = 1, plot.margin = margin(0.5, 1.5, 0.5, 0.5, "lines"), clip = "on" )
xlims |
A numeric vector of length two. The limits of the x-axis. |
ylims |
A numeric vector of length two. The limits of the y-axis. |
gap |
A numeric vector of length two. The gap between plotting area and axis to the left and bottom of the plot, as a proportion of the x-axis length. (Default: c(0.025, 0.025)) |
ext |
A numeric vector of length two. The extensions to add to the right and top of the plot, as a proportion of the x-axis length. (Default: c(0, 0)) |
ratio |
The ratio (y-axis:x-axis) to use for the plot. Ignored if both width and height are set. (Default: 1.5) |
width |
A |
height |
A |
base_size |
Base font size, given in pts. (Default: 11) |
base_line_size |
Base size for line elements. (Deault: base_size/22) |
ink, paper
|
Colour for foreground and background elements. (Defaults: "black" and "white") |
colour |
Deprecated. Use |
axis.title.margin |
Margin between axis titles and plot. (Default: 1) |
plot.margin |
Margin around entire plot (Default: margin(0.5, 0, 0.5, 0, "lines")) |
clip |
Passed to clip argument of |
Creates a forest plot with ggplot
forest_plot( panels, row.labels = NULL, row.labels.levels = NULL, rows = NULL, row.labels.heading = NULL, row.labels.space = c(0, 1, 0, 0), exponentiate = TRUE, logscale = exponentiate, panel.names = NULL, panel.headings = NULL, panel.headings.align = c("panel", "plot"), col.key = "key", col.estimate = c("estimate", "est", "beta", "loghr"), col.stderr = c("stderr", "std.error", "std.err", "se"), col.lci = NULL, col.uci = NULL, col.left = NULL, col.right = NULL, left.parse = FALSE, right.parse = FALSE, left.heading = "", right.heading = as.list(xlab), left.pos = NULL, right.pos = NULL, left.hjust = 1, right.hjust = 0, left.gap = c("I", "W"), right.gap = c("I", "W"), heading.space = 0, heading.rule = FALSE, estcolumn = TRUE, col.keep = NULL, ci.delim = ", ", digits = 2, title = "", xlab = "HR (95% CI)", xlim = NULL, xticks = NULL, nullval = NULL, col.diamond = NULL, diamond = NULL, col.bold = NULL, bold.labels = NULL, scalepoints = FALSE, minse = NULL, pointsize = 3 * base_size/11, shape = 15, plotcolour = "black", colour = plotcolour, cicolour = colour, fill = colour, ciunder = NULL, addtext = NULL, bottom.space = 0.7, left.space = NULL, right.space = NULL, mid.space = unit(5, "mm"), plot.margin = margin(2, 8, 2, 8, "mm"), panel.width = NULL, panel.height = NULL, base_size = 11, base_line_size = base_size/22, stroke = 0, diamonds.linewidth = base_line_size, row.labels.element = "marquee::element_marquee", quiet = FALSE, printplot = !quiet, showcode = !quiet, data.function = NULL, addaes = NULL, addarg = NULL, add = NULL, envir = NULL, blankrows = NULL, col.right.parse = NULL, col.left.heading = NULL, col.right.heading = NULL, col.left.pos = NULL, col.right.pos = NULL, col.left.hjust = NULL, col.right.hjust = NULL, col.left.gap = NULL, col.right.gap = NULL, col.heading.space = NULL, col.heading.rule = NULL )forest_plot( panels, row.labels = NULL, row.labels.levels = NULL, rows = NULL, row.labels.heading = NULL, row.labels.space = c(0, 1, 0, 0), exponentiate = TRUE, logscale = exponentiate, panel.names = NULL, panel.headings = NULL, panel.headings.align = c("panel", "plot"), col.key = "key", col.estimate = c("estimate", "est", "beta", "loghr"), col.stderr = c("stderr", "std.error", "std.err", "se"), col.lci = NULL, col.uci = NULL, col.left = NULL, col.right = NULL, left.parse = FALSE, right.parse = FALSE, left.heading = "", right.heading = as.list(xlab), left.pos = NULL, right.pos = NULL, left.hjust = 1, right.hjust = 0, left.gap = c("I", "W"), right.gap = c("I", "W"), heading.space = 0, heading.rule = FALSE, estcolumn = TRUE, col.keep = NULL, ci.delim = ", ", digits = 2, title = "", xlab = "HR (95% CI)", xlim = NULL, xticks = NULL, nullval = NULL, col.diamond = NULL, diamond = NULL, col.bold = NULL, bold.labels = NULL, scalepoints = FALSE, minse = NULL, pointsize = 3 * base_size/11, shape = 15, plotcolour = "black", colour = plotcolour, cicolour = colour, fill = colour, ciunder = NULL, addtext = NULL, bottom.space = 0.7, left.space = NULL, right.space = NULL, mid.space = unit(5, "mm"), plot.margin = margin(2, 8, 2, 8, "mm"), panel.width = NULL, panel.height = NULL, base_size = 11, base_line_size = base_size/22, stroke = 0, diamonds.linewidth = base_line_size, row.labels.element = "marquee::element_marquee", quiet = FALSE, printplot = !quiet, showcode = !quiet, data.function = NULL, addaes = NULL, addarg = NULL, add = NULL, envir = NULL, blankrows = NULL, col.right.parse = NULL, col.left.heading = NULL, col.right.heading = NULL, col.left.pos = NULL, col.right.pos = NULL, col.left.hjust = NULL, col.right.hjust = NULL, col.left.gap = NULL, col.right.gap = NULL, col.heading.space = NULL, col.heading.rule = NULL )
panels |
A list of data frames. These should include columns or point estimates, and standard errors or confidence interval limits. If you specify a row.labels data frame, then they must also all contain a key column with the same name (which can be specified by col.key). |
row.labels |
A data frame that contains the labels to be used for the rows of the plot. Use NA if a lower level heading is not required for a given row. |
row.labels.levels |
A character vector. The names of columns in row.labels to use as headings/subheadings/labels for labelling rows. |
rows |
If set, then only rows matching these labels (at the first level) will be included. |
row.labels.heading |
Title to be placed above row labels. |
row.labels.space |
A numeric vector specifying the space after a row label heading, at the end of a row label heading 'section'. (Default: c(0, 1, 0, 0)) |
exponentiate |
Exponentiate estimates (and CIs) before plotting. (Default: TRUE) |
logscale |
Use log scale on the axis, and add a line at null effect. (Default: exponentiate) |
panel.names |
A character vector. The names to be used for each forest plot panel. If none provided, then they will be numbered 1, 2, 3 ... |
panel.headings |
Titles to be placed above each forest plot. |
panel.headings.align |
Panel headings are by default centred over the plotting area ("panel"). Set to "plot" to centre over plotting area and text columns. |
col.key |
Name of column that links the results given in each data frame provided in panels and the labels given in row.labels. If row.labels data frame is not given, then this column will be used as row labels. (Default: "key") |
col.estimate, col.stderr, col.lci, col.uci
|
Names of columns for: point estimates, standard errors, lower and upper limits of confidence intervals. |
col.left, col.right
|
Names of columns to be printed to the left/right of the plot. |
left.parse, right.parse
|
A character vector, the same length as col.left/col.right (+ 1 if estcolumn = TRUE). Should the contents of the columns be parsed into expressions. Use "col", "heading" or "both" to parse the column content only, heading or both. |
left.heading, right.heading
|
Headings for columns. |
left.pos, right.pos
|
A unit vector to position col.left/col.right columns. |
left.hjust, right.hjust
|
A numeric vector. The horizontal justification of col.left/col.right columns. (Default: 1) |
left.gap, right.gap
|
A character vector of length two. The two characters control the gaps between the first text column and the panel, and successive text columns. (Default: c("I", "W")) |
heading.space |
Position of the titles given by left.heading and right.heading. Increase to move them up. (Default: 0) |
heading.rule |
Include a horizontal rule below column headings? (Default: FALSE) |
estcolumn |
Include column of estimates and confidence intervals to the right of each plot. (Default: TRUE) |
col.keep |
Names of additional columns to be kept in returned data frame. |
ci.delim |
Character string to separate lower and upper limits of confidence interval. (Default: ", ") |
digits |
Number of digits after decimal point to show for estimates and confidence intervals. (Default: 2) |
title |
Title to appear at the top of the plot. |
xlab |
Label to appear below the x-axis. (Default: "HR (95% CI)") |
xlim |
A numeric vector. The limits of the x axis. |
xticks |
A numeric vector. The tick points of the x axis. |
nullval |
Add a vertical reference line at this value. (If logscale == TRUE then by default it will be added at 1, but use NA not to plot this line.) |
col.diamond |
Plot estimates and CIs as diamonds. Name of a column of logical values. |
diamond |
Alternative to col.diamond. A character vectors identify the rows (using the key values) for which the estimate and CI should be plotted using a diamond. |
col.bold |
Plot text as bold. Name of a column of logical values. |
bold.labels |
A character vector identifying row labels (using key values) which should additionally be bold. (Default: NULL) |
scalepoints |
Should the points be scaled by inverse of the standard error? (Default: FALSE) |
minse |
Minimum standard error to use when scaling point size. (Default will use minimum in the data.) |
pointsize |
The (largest) size of box to use for plotting point estimates. (Default: 3 * base_size / 11) |
shape |
Shape of points. An integer, or name of a column of integers. (Default: 15 (square)) |
plotcolour |
Colour for all parts of the plot. (Default: "black") |
colour |
Colour of points. Name of a colour, or name of a column of colour names. Use a list of colour names for different colours on each panel. (Default will use plotcolour.) |
cicolour |
Colour of CI lines. Name of a colour, or name of a column of colour names. Use a list of colour names for different colours on each panel. Use a vector (or list of vectors) in conjunction with panel.width to set a different colour for narrow confidence interval lines. (Default will use colour.) |
fill |
Fill colour of points. Name of a colour, or name of a column of colour names. Use a list of colour names for different colours on each panel. (Default will use colour.) |
ciunder |
Plot CI lines before points. A logical value, or name of a column of logical values. (Default will plot CI lines after points.) |
addtext |
A list of data frames. List must be the same length as panels. Data frames should contain a column with the name specified in col.key, and one or more of:
The character strings, heterogeneity test, and trend test results will be plotted in the column of estimates and CIs, below the row with the key given in the col.key column. |
bottom.space |
Space between bottom row and axis. (Default: 0.7) |
left.space, right.space, mid.space
|
Space to the left/right/between panels. (Default mid.space: unit(5, "mm")) |
plot.margin |
Plot margin, given as margin(top, right, bottom, left, units). (Default: margin(2, 8, 2, 8, "mm")) |
panel.width, panel.height
|
Set width/height of panels. A grid::unit object, if a numeric is given assumed to be in mm. If panel.width is used, will also apply different formatting to narrow CIs. |
base_size |
base font size, given in pts. |
base_line_size |
base size for line elements |
stroke |
Size of outline of shapes. (Default: 0) |
diamonds.linewidth |
Line width for diamonds. (Default: base_line_size) |
row.labels.element |
A character string giving the name of the theme element to use for the row labels (axis.text.y). (Default: "marquee::element_marquee") |
quiet |
Set to TRUE to not print the plot nor show generated code in the RStudio 'Viewer' pane. (Default: FALSE) |
printplot |
Print the plot. (Default: !quiet) |
showcode |
Show the ggplot2 code to generate the plot in RStudio 'Viewer' pane. (Default: !quiet) |
data.function |
Name of a function to apply to data frame before plotting. |
addaes, addarg, add
|
Methods for customising the plot. See documentation for details. |
envir |
Environment in which to evaluate the plot code. May be useful when calling this function inside another function. |
blankrows |
DEPRECATED |
col.right.parse |
Deprecated. Use |
col.left.heading |
Deprecated. Use |
col.right.heading |
Deprecated. Use |
col.left.pos |
Deprecated. Use |
col.right.pos |
Deprecated. Use |
col.left.hjust |
Deprecated. Use |
col.right.hjust |
Deprecated. Use |
col.left.gap |
Deprecated. Use |
col.right.gap |
Deprecated. Use |
col.heading.space |
Deprecated. Use |
col.heading.rule |
Deprecated. Use |
The function returns the plot and ggplot2 code to create the plot. In RStudio, the ggplot2 code will be shown in the viewer.
A list:
the plot
ggplot2 code to generate the plot
From version 0.12.0, the row labels in forest plots are drawn using
marquee::element_marquee to allow for styling using markdown. When
saving it is best to use a graphics device that supports 'glyph' features
(see https://marquee.r-lib.org/reference/marquee_grob.html#rendering). For
example pdf() or the devices supplied by the ragg package, which are used
as default by ggsave() and save_figure().
To return to the old method which used the ggtext package, set
row.labels.element = "ggtext::element_markdown".
The function attempts to set the positions of columns of text and spacing
automatically. Where this does not produce a satisfactory layout, you can use
the arguments left.pos, right.pos, left.space, right.space, and
mid.space to control positions and spacing manually.
The plot will fill the vertical space available. Use plot.margin to change
the top and bottom margins as needed.
When standard errors are supplied to the shape_plot() and forest_plot()
functions, confidence intervals are calculated as 95\
using the Normal approximation method (with critical value 1.96).
The stroke argument sets the stroke aesthetic for plotted shapes. See
https://ggplot2.tidyverse.org/articles/ggplot2-specs.html for more details.
The stroke size adds to the total size of a shape, so unless stroke = 0 the
scaling of size by inverse variance will be very slightly inaccurate (but
there are probably more important things to worry about).
This geom adds a fixed horizontal and/or vertical move to ggplot2::geom_text()
geom_text_move( mapping = NULL, data = NULL, stat = "identity", position = "nudge", ..., parse = FALSE, move_x = unit(0, "pt"), move_y = unit(0, "pt"), check_overlap = FALSE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )geom_text_move( mapping = NULL, data = NULL, stat = "identity", position = "nudge", ..., parse = FALSE, move_x = unit(0, "pt"), move_y = unit(0, "pt"), check_overlap = FALSE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
parse |
If |
move_x |
Unit value to move text horizontally (Default: unit(0, "pt")) |
move_y |
Unit value to move text vertically (Default: unit(0, "pt")) |
check_overlap |
If |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom_text_move() understands the same aesthetics as ggplot2::geom_text()
This function saves a ggplot2 plot to a temporary PNG file and then embeds it in an HTML page, which is opened in the Viewer pane.
ggpreview(...)ggpreview(...)
... |
Arguments passed to |
The plot is saved using ggsave with the png device, regardless of what is specified in
the call, so any arguments not used by ggsave or png are ignored.
Make a ggplot into CKB style
plot_like_ckb(plot, ...)plot_like_ckb(plot, ...)
plot |
A ggplot2 plot |
... |
Arguments passed to ckb_style() |
A ggplot2 plot.
Prepare figure for saving
prepare_figure( figure, title = "", title.pos = grid::unit.c(unit(1.27/2, "cm"), unit(1, "npc") - unit(1.27/2, "cm")), title.just = c(0, 1), title.gpar = list(fontsize = 12, fontface = "bold"), footer = "", footer.pos = grid::unit.c(unit(1.27/2, "cm"), unit(1.27/3, "cm")), footer.just = c(0, 0), footer.gpar = list(fontsize = 9), margin = unit(c(2.27, 1.27, 1.27, 1.27), units = "cm"), size = NULL, valign = 0.5, halign = 0.5, pagesize = c("A4", "A5"), landscape = FALSE, pagedim = NULL )prepare_figure( figure, title = "", title.pos = grid::unit.c(unit(1.27/2, "cm"), unit(1, "npc") - unit(1.27/2, "cm")), title.just = c(0, 1), title.gpar = list(fontsize = 12, fontface = "bold"), footer = "", footer.pos = grid::unit.c(unit(1.27/2, "cm"), unit(1.27/3, "cm")), footer.just = c(0, 0), footer.gpar = list(fontsize = 9), margin = unit(c(2.27, 1.27, 1.27, 1.27), units = "cm"), size = NULL, valign = 0.5, halign = 0.5, pagesize = c("A4", "A5"), landscape = FALSE, pagedim = NULL )
figure |
Plot (or graphical object). |
title |
Title to be added to the page. (Default: "") |
title.pos |
Position of the title text. Default is 1/4 inch from top left of page. (Default: unit.c(unit(1.27/2, "cm"), unit(1, "npc") - unit(1.27/2, "cm"))) |
title.just |
Justification of the title text. (Default: c(0, 1)) |
title.gpar |
Graphical parameters for title. (Default: list(fontsize = 12, fontface = "bold")) |
footer |
Footer to be added to the page. (Default: "") |
footer.pos |
Position of the footer text. Default is 1/6 inch from bottom and 1/4 inch from left of page. (Default: unit.c(unit(1.27/2, "cm"), unit(1.27/3, "cm"))) |
footer.just |
Justification of the footer text. (Default: c(0, 0)) |
footer.gpar |
Graphical parameters for footer. (Default: list(fontsize = 9)) |
margin |
Margin to be placed around the plot. Default is 2.27cm top, 1.27cm (1/2 inch) other sides. (Default: unit(c(2.27, 1.27, 1.27, 1.27), units = "cm")) |
size |
A unit vector of length two (width, height). Size of plot (a width/height larger than page weight/height minus margins will be ignored), centred within margins. By default, plot will fill the space within margins. |
valign |
If size is set, where to place figure within margins. 1 = top, 0.5 = middle, 0 = bottom. (Default: 0.5) |
halign |
If size is set, where to place figure within margins. 1 = right, 0.5 = middle, 0 = left (Default: 0.5) |
pagesize |
Page size of output: "A4" or "A5". (Default: "A4") |
landscape |
Landscape page orientation? (Default: False) |
pagedim |
Dimensions (width, height) of output. Overrides pagesize and landscape arguments if used. |
Output plots as files
save_figure( figure, filename, cropped = NULL, args = NULL, args_cropped = NULL, preview = FALSE, ... )save_figure( figure, filename, cropped = NULL, args = NULL, args_cropped = NULL, preview = FALSE, ... )
figure |
Plot (or graphical object). |
filename |
Name of file to create. |
cropped |
Name of second output file of the figure without margins or title. |
args |
List of arguments passed to |
args_cropped |
List of arguments passed to |
preview |
Preview the output in the RStudio Viewer pane. (Default: False) |
... |
Other arguments passed to prepare_figure. |
Make a shape plot with ggplot2
shape_plot( data, col.x = "x", col.estimate = c("estimate", "est", "beta", "loghr"), col.stderr = c("stderr", "std.error", "std.err", "se"), col.lci = NULL, col.uci = NULL, col.n = NULL, exponentiate = FALSE, logscale = exponentiate, xlogscale = FALSE, scalepoints = FALSE, digits = 2, minse = NA, pointsize = 3 * base_size/11, col.group = NULL, shape = 15, plotcolour = "black", colour = plotcolour, cicolour = colour, fill = colour, ciunder = NULL, lines = c("none", "lmw", "lm", "connect"), xlims = NULL, ylims = NULL, height = NULL, width = NULL, gap = c(0.025, 0.025), ext = c(0.025, 0.025), ratio = 1.5, plot.margin = margin(0.5, 1.5, 0.5, 0.5, "lines"), clip = "off", base_size = 11, base_line_size = base_size/22, stroke = base_size/22, axis.title.margin = 1, xbreaks = NULL, ybreaks = NULL, xlab = "Risk factor", ylab = "Estimate (95% CI)", legend.name = "", legend.position = "top", title = NULL, quiet = FALSE, printplot = !quiet, showcode = !quiet, addaes = NULL, addarg = NULL, add = NULL, envir = NULL )shape_plot( data, col.x = "x", col.estimate = c("estimate", "est", "beta", "loghr"), col.stderr = c("stderr", "std.error", "std.err", "se"), col.lci = NULL, col.uci = NULL, col.n = NULL, exponentiate = FALSE, logscale = exponentiate, xlogscale = FALSE, scalepoints = FALSE, digits = 2, minse = NA, pointsize = 3 * base_size/11, col.group = NULL, shape = 15, plotcolour = "black", colour = plotcolour, cicolour = colour, fill = colour, ciunder = NULL, lines = c("none", "lmw", "lm", "connect"), xlims = NULL, ylims = NULL, height = NULL, width = NULL, gap = c(0.025, 0.025), ext = c(0.025, 0.025), ratio = 1.5, plot.margin = margin(0.5, 1.5, 0.5, 0.5, "lines"), clip = "off", base_size = 11, base_line_size = base_size/22, stroke = base_size/22, axis.title.margin = 1, xbreaks = NULL, ybreaks = NULL, xlab = "Risk factor", ylab = "Estimate (95% CI)", legend.name = "", legend.position = "top", title = NULL, quiet = FALSE, printplot = !quiet, showcode = !quiet, addaes = NULL, addarg = NULL, add = NULL, envir = NULL )
data |
The data frame containing estimates to be plotted. |
col.x |
Name of column that provides the x-axis value (e.g. exposure, risk factor, dependent variable). (Default: "x") |
col.estimate |
Name of column that provides point estimates. (Default: "estimate") |
col.stderr |
Name of column that provides standard errors. (Default: "stderr") |
col.lci |
Name of column that provides lower limit of confidence intervals. |
col.uci |
Name of column that provides upper limit of confidence intervals. |
col.n |
Name of column that provides number to be plotted below CIs. |
exponentiate |
Exponentiate estimates (and CIs) before plotting, use log scale on the axis. (Default: FALSE) |
logscale |
Use log scale for the y axis. (Default: exponentiate) |
xlogscale |
Use log scale for the x axis. (Default: FALSE) |
scalepoints |
Should the points be scaled by inverse of the standard error? (Default: FALSE) |
digits |
Number of digits to use in text of estimates. |
minse |
Minimum standard error to use when scaling point size. (Default will use minimum in the data.) |
pointsize |
The (largest) size of box to use for plotting point estimates. (Default: 3 * base_size / 11) |
col.group |
Name of column that groups the estimates. (Default: NULL) |
shape |
Shape of points. An integer, or name of a column of integers. (Default: 15) |
plotcolour |
Colour for non-data aspects of the plot. (Default: "black") |
colour |
Colour of points. Name of a colour, or name of a column of colour names. (Default will use plotcolour) |
cicolour |
Colour of CI lines. Colour of CI lines. Name of a colour, or name of a column of colour names. (Default will use plotcolour) |
fill |
Fill colour of points. Fill colour of points. Name of a colour, or name of a column of colour names. (Default will use plotcolour) |
ciunder |
Plot CI lines before points. A logical value, or name of a column of logical values. (Default will plot CI lines after points.) |
lines |
Add lines to the plot. "lmw" = Linear fit through estimates, weighted by inverse variance. "lm" = Unweighted linear fit through estimates. "connect" = Lines connecting each estimate. (Default: "none") |
xlims |
A numeric vector of length two. The limits of the x-axis. |
ylims |
A numeric vector of length two. The limits of the y-axis. |
height |
Panel height to use and apply different formatting to short CIs. A grid::unit() object, or if numeric is assumed to be in mm. |
width |
Panel width.A grid::unit() object, or if numeric is assumed to be in mm. |
gap |
A numeric vector of length two. The gap between plotting area and axis to the left and bottom of the plot, as a proportion of the x-axis length. (Default: c(0.025, 0.025)) |
ext |
A numeric vector of length two. The extensions to add to the right and top of the plot, as a proportion of the x-axis length. (Default: c(0.025, 0.025)) |
ratio |
The ratio (y-axis:x-axis) to use for the plot. (Default: 1.5) |
plot.margin |
Plot margin, given as margin(top, right, bottom, left, units). (Default: margin(0.5, 1.5, 0.5, 0.5, "lines")) |
clip |
Passed to clip argument of |
base_size |
Base font size, given in pts. (Default: 11) |
base_line_size |
Base size for line elements. (Deault: base_size/22) |
stroke |
Size of outline of shapes. (Default: base_size/22) |
axis.title.margin |
Margin between axis titles and plot. (Default: 1) |
xbreaks |
Breaks for the x axis. Passed to ggplots::scale_x_continuous. (Default: NULL) |
ybreaks |
Breaks for the y axis. Passed to ggplots::scale_y_continuous. (Default: NULL) |
xlab |
Label for x-axis. (Default: "Risk factor") |
ylab |
Label for y-axis. (Default: "Estimate (95% CI)") |
legend.name |
The name of the colour scale/legend for groups. (Default: "") |
legend.position |
Position of the legend for groups ("none", "left", "right", "bottom", "top", or two-element numeric vector). (Default: "top") |
title |
Plot title. (Default: NULL) |
quiet |
Set to TRUE to not print the plot nor show generated code in the RStudio 'Viewer' pane. (Default: FALSE) |
printplot |
Print the plot. (Default: !quiet) |
showcode |
Show the ggplot2 code to generate the plot in RStudio 'Viewer' pane. (Default: !quiet) |
addaes, addarg, add
|
Methods for customising the plot. See documentation for details. |
envir |
Environment in which to evaluate the plot code. May be useful when calling this function inside another function. |
A list:
the plot
ggplot2 code to generate the plot
When standard errors are supplied to the shape_plot() and forest_plot()
functions, confidence intervals are calculated as 95\
using the Normal approximation method (with critical value 1.96).
The stroke argument sets the stroke aesthetic for plotted shapes. See
https://ggplot2.tidyverse.org/articles/ggplot2-specs.html for more details.
The stroke size adds to total size of a shape, so unless stroke = 0 the
scaling of size by inverse variance will be slightly inaccurate (but there
are probably more important things to worry about).
A ggplot2 theme, based on theme_bw.
theme_ckb( base_size = 11, base_line_size = base_size/22, ink = "black", paper = "white", colour = NULL, axis.title.margin = 1, plot.margin = margin(0.5, 1.5, 0.5, 0.5, "lines"), ... )theme_ckb( base_size = 11, base_line_size = base_size/22, ink = "black", paper = "white", colour = NULL, axis.title.margin = 1, plot.margin = margin(0.5, 1.5, 0.5, 0.5, "lines"), ... )
base_size |
Base font size, given in pts. (Default: 11) |
base_line_size |
Base size for line elements. (Deault: base_size/22) |
ink, paper
|
Colour for foreground and background elements. (Defaults: "black" and "white") |
colour |
Deprecated. Use |
axis.title.margin |
Margin between axis titles and plot. (Default: 1) |
plot.margin |
Margin around entire plot (Default: margin(0.5, 0, 0.5, 0, "lines")) |
... |
Arguments passed to |