[Genabel-commits] r1582 - in pkg/MetABEL: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Feb 3 16:07:44 CET 2014
Author: lckarssen
Date: 2014-02-03 16:07:43 +0100 (Mon, 03 Feb 2014)
New Revision: 1582
Modified:
pkg/MetABEL/R/forestplot.R
pkg/MetABEL/man/forestplot.Rd
Log:
Updates to MetABEL's forestplot function:
- Removed ticks on the vertical axis. They had no meaning and confused people: http://forum.genabel.org/viewtopic.php?f=6&t=845&p=1721#p1715
- Removed the vertical axis label by default. The user can set it to their need
- Converted the horizontal axis label to show a proper \beta instead of "Beta", this can be changed by the user, e.g. to add a unit.
- Changed the "Chi2" text to Greek/math font: \chi^2.
- The vertical line at x=0 is now dashed
- Converted the documentation to roxygen2 format.
Modified: pkg/MetABEL/R/forestplot.R
===================================================================
--- pkg/MetABEL/R/forestplot.R 2014-02-03 14:56:00 UTC (rev 1581)
+++ pkg/MetABEL/R/forestplot.R 2014-02-03 15:07:43 UTC (rev 1582)
@@ -1,7 +1,29 @@
+##' Function to draw meta-analysis forest plots
+##'
+##' This function creates forest plots from meta-analysis data.
+##'
+##' @param estimate Vector of effect estimates
+##' @param se Vector of standard errors
+##' @param labels Vector of labels for the individual studies
+##' (default: Study 1, Study 2, etc.)
+##' @param CI Confidence interval (default: 0.95)
+##' @param xexp Whether the effect values are to be depicted on an
+##' exponential scale (default: \code{FALSE})
+##' @param xlab Label for the horizontal axis (default: \eqn{\beta})
+##' @param ylab Label for the horizontal axis (default: empty)
+##' @param ... Arguments passed to the \code{plot} function,
+##' e.g. \code{main="My plot"}
+##' @author Yurii Aulchenko, Lennart C. Karssen
+##' @keywords hplot
+##' @export
+##' @examples
+##' beta <- c(0.16, 0.091, 0.072, -0.03)
+##' se <- c(0.07, 0.042, 0.048, 0.12)
+##' forestplot(beta, se, main="Example plot")
"forestplot" <-
function(estimate, se,
labels=paste("Study", c(1:length(estimate))),
- CI=0.95, xexp=FALSE, ...) {
+ CI=0.95, xexp=FALSE, xlab=expression(beta), ylab="", ...) {
hoff <- 3
del <- 10
mea <- !is.na(estimate)
@@ -50,18 +72,23 @@
if (any(is.na(se))) stop("se contains NAs")
plot(x=c(cntr, cntr), y=c(0, hgt), xlim=c(minv, maxv),
- ylim=c(0, hgt), type="l", lwd=2, xlab="Beta", ...)
+ ylim=c(0, hgt), type="l", lwd=2, lty=2,
+ xlab=xlab, ylab=ylab, yaxt='n', ...)
+ ## Draw the bars for the individual studies
for (i in c(1:(length(estimate)-1))) {
points(x=c(lower[i], upper[i]), y=c((i) * del, (i) * del),
type="l", lwd=2)
points(x=c(estimate[i]), y=c((i) * del), pch=19, cex=1)
- text(estimate[i], i * del + 1,
- paste(labels[i], " (Chi2=", chi2[i], ", P=", p[i],
- ")", sep=""),
- pos=3, cex=.7)
+
+ labeltext <- bquote(
+ .(labels[i]) ~ "(" * chi^2 ~ "=" ~ .(chi2[i]) * ","
+ ~ italic(P) ~ "=" ~ .(p[i]) * ")"
+ )
+ text(estimate[i], i * del + 1, labeltext, pos=3, cex=.7)
}
+ ## Draw diamond of the estimate
for (i in c(length(estimate))) {
points(x=c(lower[i], estimate[i]),
y=c((i) * del, (i) * del + hoff),
@@ -75,9 +102,11 @@
points(x=c(lower[i], estimate[i]),
y=c((i) * del, (i) * del - hoff),
type="l", lwd=2)
- text(estimate[i], i * del + 5,
- paste(labels[i], " (Chi2=", chi2[i], ", P=", p[i],
- ")", sep=""),
- pos=3, cex=1)
+
+ labeltext <-bquote(
+ .(labels[i]) ~ "(" * chi^2 ~ "=" ~ .(chi2[i]) * ","
+ ~ italic(P) ~ "=" ~ .(p[i]) * ")"
+ )
+ text(estimate[i], i * del + 5, labeltext, pos=3, cex=1)
}
}
Modified: pkg/MetABEL/man/forestplot.Rd
===================================================================
--- pkg/MetABEL/man/forestplot.Rd 2014-02-03 14:56:00 UTC (rev 1581)
+++ pkg/MetABEL/man/forestplot.Rd 2014-02-03 15:07:43 UTC (rev 1582)
@@ -1,38 +1,42 @@
-\name{forestplot}
-\alias{forestplot}
-\title{Forest plot}
-\description{
- Function to draw meta-analysis forest plots
-}
-
-\usage{
- forestplot(estimate, se, labels = paste("Study", c(1:length(estimate))),
- CI = 0.95, xexp = FALSE, ...)
-}
-
-\arguments{
- \item{estimate}{Vector of effect estimates}
- \item{se}{Vector of standard errors}
- \item{labels}{Individual study labels}
- \item{CI}{Confidence interval, e.g. 0.95}
- \item{xexp}{Whether the effect values are to be depicted on exponential scale}
- \item{\dots}{Arguments passed to plot function, e.g. main = "My plot"}
-}
-
-%\details{
-%}
-%\value{
-%}
-%\references{ ~put references to the literature/web site here ~ }
-\author{Yurii Aulchenko}
-%\note{ ~~further notes~~
-%}
-%\seealso{ ~~objects to See Also as \code{\link{help}}, ~~~ }
-\examples{
- beta <- c(0.16, 0.091, 0.072, -0.03)
- se <- c(0.07, 0.042, 0.048, 0.12)
- forestplot(beta, se, main="Example plot")
-}
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{hplot}
+\name{forestplot}
+\alias{forestplot}
+\title{Function to draw meta-analysis forest plots}
+\usage{
+forestplot(estimate, se, labels = paste("Study", c(1:length(estimate))),
+ CI = 0.95, xexp = FALSE, xlab = expression(beta), ylab = "", ...)
+}
+\arguments{
+ \item{estimate}{Vector of effect estimates}
+
+ \item{se}{Vector of standard errors}
+
+ \item{labels}{Vector of labels for the individual studies
+ (default: Study 1, Study 2, etc.)}
+
+ \item{CI}{Confidence interval (default: 0.95)}
+
+ \item{xexp}{Whether the effect values are to be depicted
+ on an exponential scale (default: \code{FALSE})}
+
+ \item{xlab}{Label for the horizontal axis (default:
+ \eqn{\beta})}
+
+ \item{ylab}{Label for the horizontal axis (default:
+ empty)}
+
+ \item{...}{Arguments passed to the \code{plot} function,
+ e.g. \code{main="My plot"}}
+}
+\description{
+This function creates forest plots from meta-analysis data.
+}
+\examples{
+beta <- c(0.16, 0.091, 0.072, -0.03)
+se <- c(0.07, 0.042, 0.048, 0.12)
+forestplot(beta, se, main="Example plot")
+}
+\author{
+Yurii Aulchenko, Lennart C. Karssen
+}
+\keyword{hplot}
+
More information about the Genabel-commits
mailing list