Description Usage Arguments Details Value Author(s) See Also Examples
forestplot2 is based on the rmeta 2.16
forestplot
function. This
function resolves some limitations of the original
functions such as:
Adding expressions: Allows use of expressions, e.g. expression(beta)
Multiple bands: Using multiple confidence bands for the same label
Autosize: Adapts to windows size
1 2 3 4 5 6 7 8 9 10 11 | forestplot2(labeltext, mean, lower, upper, align = NULL, is.summary = FALSE,
fontfamily.summary = NULL, fontfamily.labelrow = NULL, clip = c(-Inf,
Inf), xlab = "", zero = 0, graphwidth = "auto", lineheight = "auto",
col = fpColors(), xlog = FALSE, xticks = NULL, xticks.digits = 2,
lwd.xaxis = NULL, lwd.zero = NULL, lwd.ci = NULL, cex = 1,
cex.axis = cex * 0.6, boxsize = NULL, mar = unit(rep(5, times = 4),
"mm"), main = NULL, legend = NULL, legend.pos = "top",
legend.cex = cex * 0.8, legend.gp = NULL, legend.r = unit(0, "snpc"),
legend.padding = unit(ifelse(length(legend.gp) > 0, 3, 0), "mm"),
legend.title = NULL, new_page = FALSE, confintNormalFn = fpDrawNormalCI,
confintSummaryFn = fpDrawSummaryCI, legendMarkerFn = NULL, ...)
|
labeltext |
A list, matrix, vector or expression with the names of each
row. The list should be wrapped in m x n number to resemble a matrix:
|
mean |
A vector or a matrix with the averages |
lower |
The lower bound of the confidence interval for the forestplot, needs to be the same format as the mean, i.e. matrix/vector of equal columns & length |
upper |
The upper bound of the confidence interval for the forestplot, needs to be the same format as the mean, i.e. matrix/vector of equal columns & length |
align |
Vector giving alignment (l,r,c) for columns of table |
is.summary |
A vector indicating by TRUE/FALSE if the value is a summary value which means that it will have a different font-style. |
fontfamily.summary |
The fontfamily of the summary |
fontfamily.labelrow |
The fontfamily of a regular row |
clip |
Lower and upper limits for clipping confidence intervals to arrows |
xlab |
x-axis label |
zero |
x-axis coordinate for zero line |
graphwidth |
Width of confidence interval graph, see |
lineheight |
Height of the graph. By default this is |
col |
See |
xlog |
If TRUE, x-axis tick marks are exponentiated |
xticks |
Optional user-specified x-axis tick marks. Specify NULL to use the defaults, numeric(0) to omit the x-axis. |
xticks.digits |
The number of digits to allow in the x-axis if this is created by default. |
lwd.xaxis |
lwd for the xaxis |
lwd.zero |
lwd for the vertical line that gives the no-effect line |
lwd.ci |
lwd for the confidence bands |
cex |
The font adjustment |
cex.axis |
The font adjustment for the x-xaxis, defaults to 60 % of the cex parameter. |
boxsize |
Override the default box size based on precision |
mar |
A numerical vector of the form c(bottom, left, top, right) of the type |
main |
The title of the plot if any, default |
legend |
Legen corresponding to the number of bars. |
legend.pos |
The position of the legend, either at the "top" or the "right" unlesss
positioned inside the plot. If you want the legend to be positioned inside the plot
then you have to provide a list with the same x & y qualities as |
legend.cex |
The cex size of the legend, defaults to 80 % procent of cex parameter. |
legend.gp |
The |
legend.r |
The box can have rounded edges, check out |
legend.padding |
The padding for the legend box, only used if box is drawn. This is the distance from the border to the text/boxes of the legend. |
legend.title |
The title of the legend if any, default to NULL |
new_page |
If you want the plot to appear on a new blank page then set this to |
confintNormalFn |
You can specify exactly how the line with the box is
drawn for the normal (i.e. non-summary) confidence interval by changing this
parameter to your own function or some of the alternatives provided in the package.
It defaults to the box function |
confintSummaryFn |
Same as previous argument but for the summary outputs
and it defaults to |
legendMarkerFn |
What type of function should be used for drawing the
legends, this can be a list if you want different functions. It defaults to
a box if you have anything else than a single function or the number of columns
in the |
... |
Passed on to the |
Using multiple bands for the same label can be interesting when one wants to compare different outcomer. It can also be an alternative when you want to show both crude and adjusted estimates.
Known issues: the x-axis does not entirely respect the margin. Autosizing boxes is not always the best option, try to set these manually as much as possible.
void
Max Gordon, Thomas Lumley
Other forestplot functions: fpColors
;
fpDrawCircleCI
,
fpDrawDiamondCI
,
fpDrawNormalCI
,
fpDrawPointCI
,
fpDrawSummaryCI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | ##############################################################
# Simple examples of how to do a forestplot with forestplot2 #
##############################################################
ask <- par(ask=TRUE)
library(grid)
# A basic example, create some fake data
row_names <- list(list("test = 1", expression(test >= 2)))
test_data <- data.frame(coef=c(1.59, 1.24),
low=c(1.4, 0.78),
high=c(1.8, 1.55))
forestplot2(row_names,
test_data$coef,
test_data$low,
test_data$high,
zero = 1,
cex = 2,
lineheight = "auto",
xlab = "Lab axis txt",
new_page = TRUE)
# Print two plots side by side using the grid
# package's layout option for viewports
grid.newpage()
pushViewport(viewport(layout = grid.layout(1, 2)))
pushViewport(viewport(layout.pos.col = 1))
forestplot2(row_names,
test_data$coef,
test_data$low,
test_data$high,
zero = 1,
cex = 2,
lineheight = "auto",
xlab = "Lab axis txt")
popViewport()
pushViewport(viewport(layout.pos.col = 2))
forestplot2(row_names,
test_data$coef,
test_data$low,
test_data$high,
zero = 1,
cex = 2,
lineheight = "auto",
xlab = "Lab axis txt")
popViewport()
popViewport()
# An advanced test
test_data <- data.frame(coef1=c(1, 1.59, 1.3, 1.24),
coef2=c(1, 1.7, 1.4, 1.04),
low1=c(1, 1.3, 1.1, 0.99),
low2=c(1, 1.6, 1.2, 0.7),
high1=c(1, 1.94, 1.6, 1.55),
high2=c(1, 1.8, 1.55, 1.33))
col_no <- grep("coef", colnames(test_data))
row_names <- list(
list("Category 1", "Category 2", "Category 3", expression(Category >= 4)),
list("ref",
substitute(expression(bar(x) == val),
list(val = round(rowMeans(test_data[2, col_no]), 2))),
substitute(expression(bar(x) == val),
list(val = round(rowMeans(test_data[3, col_no]), 2))),
substitute(expression(bar(x) == val),
list(val = round(rowMeans(test_data[4, col_no]), 2))))
)
coef <- with(test_data, cbind(coef1, coef2))
low <- with(test_data, cbind(low1, low2))
high <- with(test_data, cbind(high1, high2))
forestplot2(row_names, coef, low, high,
main="Cool study",
zero = 1, boxsize=0.5,
col=fpColors(box=c("royalblue", "gold"),
line=c("darkblue", "orange"),
summary=c("darkblue", "red")),
xlab="The estimates",
new_page = TRUE,
legend.title="Group",
legend=c("Treatment", "Placebo"),
legend.pos=list("topright"),
legend.r = unit(.1, "snpc"),
legend.gp = gpar(col="#CCCCCC", lwd=1.5))
# An example of how the exponential works
test_data <- data.frame(coef=c(2.45, 0.43),
low=c(1.5, 0.25),
high=c(4, 0.75),
boxsize=c(0.5, 0.5))
row_names <- cbind(c("Name", "Variable A", "Variable B"),
c("HR", test_data$coef))
test_data <- rbind(rep(NA, 3), test_data)
forestplot2(labeltext = row_names,
is.summary=c(TRUE, FALSE, FALSE),
mean = test_data$coef,
lower = test_data$low,
upper = test_data$high,
boxsize = test_data$boxsize,
zero = 1,
xlog = TRUE,
col = fpColors(lines="red", box="darkred"),
new_page = TRUE)
par(ask=ask)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.