# NOT RUN {
library(Publish)
data(CiTable)
## columns 6, 7, 8, 9 contain the hazard ratio, the lower
## and the upper confidence limits and the p-values, respectively
head(CiTable[,6:9])
## columns 1,2,3,4,5 contain the labels
head(CiTable[,1:5])
## A first draft version of the plot is obtained as follows
plotConfidence(x=CiTable[,6:8], labels=CiTable[,1:5])
## The graph consist of at most three blocks:
##
## block 1: labels
## block 2: printed values of the confidence intervals
## block 3: graphical presentation of the confidence intervals
##
## NOTE: block 3 appears always, the user decides if also
## blocks 1, 2 should appear
##
## The blocks are arranged with the function layout
## and the default order is 1,3,2 such that the graphical
## display of the confidence intervals appears in the middle
##
## the order of appearance of the three blocks can be changed as follows
plotConfidence(x=CiTable[,6:8],
labels=CiTable[,1:5],
order=c(1,3,2))
plotConfidence(x=CiTable[,6:8],
labels=CiTable[,1:5],
order=c(2,3,1))
## if there are only two blocks the order is 1, 2
plotConfidence(x=CiTable[,6:8],
labels=CiTable[,1:5],
values=FALSE,
order=c(2,1))
plotConfidence(x=CiTable[,6:8],
labels=CiTable[,1:5],
values=FALSE,
order=c(1,2))
## The relative size of the blocks needs to be controlled manually
## by using the argument xratio. If there are only two blocks
plotConfidence(x=CiTable[,6:8],
labels=CiTable[,1:5],xratio=c(0.4,0.15))
## The amount of space on the left and right margin can be controlled
## as follows:
plotConfidence(x=CiTable[,6:8],labels=CiTable[,1:5],xratio=c(0.4,0.15),
leftmargin=0.1,rightmargin=0.00)
## The actual size of the current graphics device determines
## the size of the figures and the space between them.
## The sizes and line widths are increased as follows:
plotConfidence(x=CiTable[,6:8],
xlab="Hazard ratio",
labels=CiTable[,1:5],
cex=1.3,
lwd=3,
xaxis.lwd=1.3,
xaxis.cex=1.3)
## Note that 'cex' of axis ticks is controlled via 'par' but
## cex of the label via argument 'cex' of 'mtext'.
## The sizes and line widths are decreased as follows:
plotConfidence(x=CiTable[,6:8],
labels=CiTable[,1:5],
cex=0.8,
lwd=0.8,
xaxis.lwd=0.8,
xaxis.cex=0.8)
## Another good news is that all figures can be controlled separately
## The size of the graphic device can be controlled in the usual way, e.g.:
# }
# NOT RUN {
pdf("~/tmp/testCI.pdf",width=8,height=8)
plotConfidence(x=CiTable[,6:8],
labels=CiTable[,1:5])
dev.off()
# }
# NOT RUN {
## More control of the x-axis and confidence intervals that
## stretch outside the x-range.
plotConfidence(x=CiTable[,6:8],
xlab="Hazard ratio",
xlab.line=1.8,
xaxis.at=c(0.8,1,1.3),
labels=CiTable[,1:5],xlim=c(0.8,1.3))
## log-scale
plotConfidence(x=CiTable[,6:8],
xlab="Hazard ratio",
xlab.line=1.8,
xaxis.at=c(0.8,1,1.3),
labels=CiTable[,1:5],xlim=c(0.8,1.3),plot.log="x")
## More pronounced arrows
## Coloured xlab expression
plotConfidence(x=CiTable[,6:8],
xlab=expression(HR[1](s)),
xlab.line=1.8,
xlab.col="darkred",
extremearrows.angle=50,
extremearrows.length=0.1,
labels=CiTable[,1:5],xlim=c(0.8,1.3))
## Controlling the labels and their titles
## and the values and their titles
plotConfidence(x=CiTable[,6:8],
labels=CiTable[,1:5],
xlab="Hazard ratio",
title.values=expression(bold(HR (CI[95]))),
title.labels=c("Drug/Time","Dose","Mean","St.dev.","N"),
factor.reference.pos=c(1,10,19),
cex=1.3,
xaxis.at=c(0.75,1,1.25,1.5,2))
## For factor reference groups, one may want to replace the
## confidence intervals by the word Reference, as in the previous example.
## To change the word 'Reference' we use the argument factor.reference.label:
## To change the plot symbol for the reference lines factor.reference.pch
## To remove the plot symbol use 'NA' as follows:
plotConfidence(x=CiTable[,6:8],
labels=CiTable[,1:5],
xlab="Hazard ratio",
factor.reference.label="Ref",
title.values=expression(bold(HR (CI[95]))),
title.labels=c("Drug/Time","Dose","Mean","St.dev.","N"),
factor.reference.pos=c(1,10,19),
factor.reference.pch=NA,
cex=1.3,
xaxis.at=c(0.75,1,1.25,1.5,2))
## changing the style of the graphical confidence intervals
plotConfidence(x=CiTable[,6:8],
labels=CiTable[,1:5],
xlab="Hazard ratio",
factor.reference.pos=c(1,10,19),
points.pch=15,
points.col=rainbow(27),
points.cex=2,
arrows.col="darkblue",
cex=1.3,
order=c(1,3,2),
xaxis.at=c(0.75,1,1.25,1.5))
## the values block of the graph can have multiple columns as well
## to illustrate this we create the confidence intervals
## before calling the function and then cbind them
## to the pvalues
HR <- pubformat(CiTable[,6])
CI95 <- formatCI(lower=CiTable[,7],upper=CiTable[,8],format="(l-u)")
pval <- format.pval(CiTable[,9],digits=3,eps=10^{-3})
pval[pval=="NA"] <- ""
plotConfidence(x=CiTable[,6:8],
labels=CiTable[,1:5],
values=list("HR"=HR,"CI-95"=CI95,"P-value"=pval),
cex=1.2,
xratio=c(0.5,0.3))
## Finally, vertical blocks can be delimited with background color
## NOTE: this may slow things down and potentially create
## large figures (many bytes)
col1 <- rep(c(prodlim::dimColor("green",density=22),
prodlim::dimColor("green")),length.out=9)
col2 <- rep(c(prodlim::dimColor("orange",density=22),
prodlim::dimColor("orange")),length.out=9)
col3 <- rep(c(prodlim::dimColor("blue",density=22),
prodlim::dimColor("blue")),length.out=9)
plotConfidence(x=CiTable[,6:8],
labels=CiTable[,1:5],
stripes=c(1,0,1),
stripes.col=c(col1,col2,col3))
plotConfidence(x=CiTable[,6:8],
labels=CiTable[,1:5],
stripes=c(1,1,1),
stripes.col=c(col1,col2,col3))
threegreens <- c(prodlim::dimColor("green",density=55),
prodlim::dimColor("green",density=33),
prodlim::dimColor("green",density=22))
plotConfidence(x=CiTable[,6:8],
labels=CiTable[,1:5],
values=FALSE,
xlim=c(0.75,1.5),
stripes=c(1,1,1),
xratio=c(0.5,0.15),
stripes.horizontal=c(0,9,18,27)+0.5,
stripes.col=threegreens)
# }
Run the code above in your browser using DataLab