R: Plot estimates with confidence limits (forest plot)
plotEst
R Documentation
Plot estimates with confidence limits (forest plot)
Description
Plots parameter estimates with confidence intervals, annotated with
parameter names. A dot is plotted at the estimate and a horizontal
line extending from the lower to the upper limit is superimposed.
Matrix with three columns: Estimate, lower limit, upper
limit. If a model object is supplied, ci.lin is
invoked for this object first.
y
Vertical position of the lines.
txt
Annotation of the estimates. Either a character vector or
an expression vector.
txtpos
Vertical position of the text. Defaults to y.
ylim
Extent of the vertical axis.
xlab
Annotation of the horizontal axis.
xtic
Location of tickmarks on the x-axis.
xlim
Extent of the x-axis.
xlog
Should the x-axis be logarithmic?
pch
What symbol should be used?
cex
Expansion of the symbol.
col
Colour of the points and lines.
col.txt
Colour of the text annotating the estimates.
font.txt
Font for the text annotating the estimates.
col.lines
Colour of the lines.
col.points
Colour of the symbol.
lwd
Thickness of the lines.
vref
Where should vertical reference line(s) be drawn?
grid
If TRUE, vertical gridlines are drawn at the
tickmarks. If a numerical vector is given vertical lines are drawn
at grid.
col.grid
Colour of the vertical gridlines
restore.par
Should the graphics parameters be restored? If set
to FALSE the coordinate system will still be available for
additional plotting, and par("mai") will still have the very
large value set in order to make room for the labelling of the
estimates.
...
Arguments passed on to ci.lin when a model object is
supplied as ests.
Details
plotEst makes a news plot, whereas linesEst and
pointsEst (identical functions) adds to an existing plot.
If a model object of class "glm", "coxph", "clogistic" or
"gnlm" is supplied the argument xlog defaults to
TRUE, and exponentiated estimates are extracted by default.
# Bogus data and a linear model
f <- factor( sample( letters[1:5], 100, replace=TRUE ) )
x <- rnorm( 100 )
y <- 5 + 2 * as.integer( f ) + 0.8 * x + rnorm(100) * 2
m1 <- lm( y ~ f )
# Produce some confidence intervals for contrast to first level
( cf <- ci.lin( m1, subset=-1 )[,-(2:4)] )
# Plots with increasing amounts of bells and whistles
par( mfcol=c(3,2), mar=c(3,3,2,1) )
plotEst( cf )
plotEst( cf, grid=TRUE, cex=2, lwd=3 )
plotEst( cf, grid=TRUE, cex=2, col.points="red", col.lines="green" )
plotEst( cf, grid=TRUE, cex=2, col.points="red", col.lines="green",
xlog=TRUE, xtic=c(1:8), xlim=c(0.8,6) )
rownames( cf )[1] <- "Contrast to fa:\n fb"
plotEst( cf, grid=TRUE, cex=2, col.points=rainbow(4),
col.lines=rainbow(4), vref=1 )
#
etxt <- expression("Plain text, qouted",
"combined with maths:"*sqrt(a)*phi[c],
f^d*" Hb"*A[1][c],
eff^e*" kg/"*m^2)
plotEst( cf, txt=etxt, grid=TRUE, cex=2, col.points=rainbow(4),
col.lines =rainbow(4), vref=1 )
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(Epi)
Attaching package: 'Epi'
The following object is masked from 'package:base':
merge.data.frame
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Epi/plotEst.Rd_%03d_medium.png", width=480, height=480)
> ### Name: plotEst
> ### Title: Plot estimates with confidence limits (forest plot)
> ### Aliases: plotEst pointsEst linesEst
> ### Keywords: hplot models
>
> ### ** Examples
>
> # Bogus data and a linear model
> f <- factor( sample( letters[1:5], 100, replace=TRUE ) )
> x <- rnorm( 100 )
> y <- 5 + 2 * as.integer( f ) + 0.8 * x + rnorm(100) * 2
> m1 <- lm( y ~ f )
>
> # Produce some confidence intervals for contrast to first level
> ( cf <- ci.lin( m1, subset=-1 )[,-(2:4)] )
Estimate 2.5% 97.5%
fb 1.003188 -0.4829802 2.489357
fc 3.224087 1.8997136 4.548461
fd 5.158794 3.8089143 6.508674
fe 7.044878 5.8830865 8.206669
>
> # Plots with increasing amounts of bells and whistles
> par( mfcol=c(3,2), mar=c(3,3,2,1) )
> plotEst( cf )
> plotEst( cf, grid=TRUE, cex=2, lwd=3 )
> plotEst( cf, grid=TRUE, cex=2, col.points="red", col.lines="green" )
> plotEst( cf, grid=TRUE, cex=2, col.points="red", col.lines="green",
+ xlog=TRUE, xtic=c(1:8), xlim=c(0.8,6) )
> rownames( cf )[1] <- "Contrast to fa:\n fb"
> plotEst( cf, grid=TRUE, cex=2, col.points=rainbow(4),
+ col.lines=rainbow(4), vref=1 )
> #
> etxt <- expression("Plain text, qouted",
+ "combined with maths:"*sqrt(a)*phi[c],
+ f^d*" Hb"*A[1][c],
+ eff^e*" kg/"*m^2)
> plotEst( cf, txt=etxt, grid=TRUE, cex=2, col.points=rainbow(4),
+ col.lines =rainbow(4), vref=1 )
>
>
>
>
>
> dev.off()
null device
1
>