if (FALSE) {
# load data (CLSI EP05-A2 Within-Lab Precision Experiment)
data(dataEP05A2_3)
# two additional classification variables (without real interpretation)
dataEP05A2_3$user <- sample(rep(c(1,2), 40))
dataEP05A2_3$cls2 <- sample(rep(c(1,2), 40))
# plot data as variability-chart, using automatically determined parameter
# settings (see 'dynParmSet')
varPlot(y~day/run, dataEP05A2_3)
# display intercept (total mean)
varPlot(y~day/run, dataEP05A2_3, MeanLine=list(var="int"))
# use custom VC-names
varPlot(y~day/run, dataEP05A2_3, VCnam=list(text=c("_Day", "_Run")))
# re-plot now also indicating dayly means as blue horizontal lines
varPlot(y~day/run, dataEP05A2_3, MeanLine=list(var=c("day", "int"), col="blue"))
# now use variable-names in names of individual factor-levels and use a different
# notation of the nesting structure
varPlot(y~day+day:run, dataEP05A2_3, useVarNam=TRUE)
# rotate names of VCs to fit into cells
varPlot( y~day+day:run, dataEP05A2_3, useVarNam=TRUE,
VarLab=list(list(font=2, srt=60), list(srt=90)))
# use alternating backgrounds for each level of factor "day"
# (top-level factor is default)
# use a simplified model formula (NOTE: only valid for function 'varPlot')
varPlot(y~day+run, dataEP05A2_3, BG=list(col=c("gray70", "gray90"), border=NA))
# now also color the corresponding row in the table accordingly
varPlot( y~day+run, dataEP05A2_3,
BG=list(col=c("gray70", "gray90"), border=NA, col.table=TRUE))
# assign different point-colors according to a classification variable
# not part of the model (artificial example in this case)
varPlot( y~day+day:run, dataEP05A2_3, mar=c(1,5,1,7), VCnam=list(side=4),
Points=list(col=list(var="user", col=c("red", "green"))) )
# always check order of factor levels before annotating
order(unique(dataEP05A2_3$user))
# add legend to right margin
legend.m(fill=c("green", "red"), legend=c("User 1", "User 2"))
# assign different plotting symbols according to a classification
# variable not part of the model
varPlot( y~day+day:run, dataEP05A2_3, mar=c(1,5,1,7), VCnam=list(side=4),
Points=list(pch=list(var="user", pch=c(2, 8))) )
# add legend to right margin
legend.m(pch=c(8,2), legend=c("User 1", "User 2"))
# assign custom plotting symbols by combining 'pch' and 'bg'
varPlot( y~day+day:run, dataEP05A2_3,
Points=list(pch=list(var="user", pch=c(21, 24)),
bg=list( var="user", bg=c("lightblue", "yellow"))) )
# assign custom plotting symbols by combining 'pch', 'bg', and 'cex'
varPlot( y~day+day:run, dataEP05A2_3,
Points=list(pch=list(var="user", pch=c(21, 24)),
bg =list(var="user", bg=c("lightblue", "yellow")),
cex=list(var="user", cex=c(2,1))) )
# now combine point-coloring and plotting symbols
# to indicate two additional classification variables
varPlot( y~day+day:run, dataEP05A2_3, mar=c(1,5,1,10),
VCnam=list(side=4, cex=1.5),
Points=list(col=list(var="user", col=c("red", "darkgreen")),
pch=list(var="cls2", pch=c(21, 22)),
bg =list(var="user", bg =c("orange", "green"))) )
# add legend to (right) margin
legend.m( margin="right", pch=c(21, 22, 22, 22),
pt.bg=c("white", "white", "orange", "green"),
col=c("black", "black", "white", "white"),
pt.cex=c(1.75, 1.75, 2, 2),
legend=c("Cls2=1", "Cls2=2", "User=2", "User=1"),
cex=1.5)
# use blue lines between each level of factor "run"
varPlot(y~day/run, dataEP05A2_3, BG=list(var="run", border="blue"))
# plot SDs for each run
varPlot(y~day+day:run, dataEP05A2_3, type=2)
# use CV instead of SD
varPlot(y~day/run, dataEP05A2_3, type=2, VARtype="CV")
# now plot variability-chart and SD-plot in one window
varPlot(y~day/run, dataEP05A2_3, type=3, useVarNam=TRUE)
# now further customize the plot
varPlot( y~day/run, dataEP05A2_3, BG=list(col=c("lightgray", "gray")),
YLabel=list(font=2, col="blue", cex=1.75, text="Custom Y-Axis Label"),
VCnam=list(col="red", font=4, cex=2),
VarLab=list(list(col="blue", font=3, cex=2), list(cex=1.25, srt=-15)))
# create variability-chart of the example dataset in the CLSI EP05-A2
# guideline (listed on p.25)
data(Glucose,package="VCA")
varPlot(result~day/run, Glucose, type=3)
# use individual settings of 'VarLab' and 'VSpace' for each variance component
varPlot(result~day/run, Glucose, type=3,
VarLab=list(list(srt=45, col="red", font=2),
list(srt=90, col="blue", font=3)), VSpace=c(.25, .75))
# set individual titles for both plot when 'type=3'
# and individual 'ylim' specifications
varPlot(result~day/run, Glucose, type=3,
Title=list( list(main="Variability Chart"),
list(main="Plot of SD-Values")),
ylim=list( c(230, 260), c(0, 10)))
# more complex experimental design
data(realData)
Data <- realData[realData$PID == 1,]
varPlot(y~lot/calibration/day/run, Data, type=3)
# order levels in the tablular environment
varPlot(y~lot/calibration/day/run, Data, keep.order=FALSE)
# keeping the order as in the data set (default) was different
varPlot(y~lot/calibration/day/run, Data, keep.order=TRUE)
# improve visual appearance of the plot by alternating bg-colors
# for variable "calibration"
varPlot(y~lot/calibration/day/run, Data, type=3, keep.order=FALSE,
BG=list(var="calibration", col=c("white", "lightgray")))
# add horizontal lines indicating mean-value for each factor-level of all variables
varPlot(y~lot/calibration/day/run, Data, type=3, keep.order=FALSE,
BG=list(var="calibration",
col=c("lightgray","antiquewhite2","antiquewhite4",
"antiquewhite1","aliceblue","antiquewhite3",
"white","antiquewhite","wheat" ),
col.table=TRUE),
MeanLine=list(var=c("lot", "calibration", "day", "int"),
col=c("orange", "blue", "green", "magenta"),
lwd=c(2,2,2,2)))
# now also highlight bounds between factor levels of "lot" and "day"
# as vertical lines and extend them into the table (note that each
# variable needs its specific value for 'col.table')
varPlot(y~lot/calibration/day/run, Data, type=3, keep.order=FALSE,
BG=list(var="calibration",
col=c( "aquamarine","antiquewhite2","antiquewhite4",
"antiquewhite1","aliceblue","antiquewhite3",
"white","antiquewhite","wheat" ),
col.table=TRUE),
MeanLine=list( var=c("lot", "calibration", "day", "int"),
col=c("orange", "blue", "darkgreen", "magenta"),
lwd=c(2,2,2,2)),
VLine=list( var=c("lot", "day"), col=c("black", "skyblue1"),
lwd=c(2, 1), col.table=c(TRUE, TRUE)))
# one can use argument 'JoinLevels' to join factor-levels or a variable
# nested within a higher-level factor, 'VLine' is used to separate levels
# of variables "calibration" and "lot" with different colors
varPlot(y~calibration/lot/day/run, Data,
BG=list(var="calibration",
col=c("#f7fcfd","#e5f5f9","#ccece6","#99d8c9",
"#66c2a4","#41ae76","#238b45","#006d2c","#00441b"),
col.table=TRUE),
VLine=list(var=c("calibration", "lot"),
col=c("black", "darkgray"), lwd=c(2,1), col.table=TRUE),
JoinLevels=list(var="lot", col=c("#ffffb2","orangered","#feb24c"),
lwd=c(2,2,2)),
MeanLine=list(var="lot", col="blue", lwd=2))
# same plot demonstrating additional features applicable via 'Points'
varPlot(y~calibration/lot/day/run, Data,
BG=list(var="calibration",
col=c("#f7fcfd","#e5f5f9","#ccece6","#99d8c9",
"#66c2a4","#41ae76","#238b45","#006d2c","#00441b"),
col.table=TRUE),
VLine=list(var=c("calibration", "lot"),
col=c("black", "mediumseagreen"), lwd=c(2,1),
col.table=c(TRUE,TRUE)),
JoinLevels=list(var="lot", col=c("lightblue", "cyan", "yellow"),
lwd=c(2,2,2)),
MeanLine=list(var="lot", col="blue", lwd=2),
Points=list(pch=list(var="lot", pch=c(21, 22, 24)),
bg =list(var="lot", bg=c("lightblue", "cyan", "yellow")),
cex=1.25))
# depict measurements as boxplots
data(VCAdata1)
datS5 <- subset(VCAdata1, sample==5)
varPlot(y~device/day, datS5, Boxplot=list())
# present points as jitter-plot around box-center
varPlot(y~device/day, datS5,
Boxplot=list(jitter=1, col.box="darkgreen"),
BG=list(var="device", col=paste0("gray", c(60, 70, 80)),
col.table=TRUE),
Points=list(pch=16,
col=list(var="run", col=c("blue", "red"))),
Mean=list(col="black", cex=1, lwd=2),
VLine=list(var="day", col="white"))
# add legend
legend( "topright", legend=c("run 1", "run 2"),
fill=c("blue", "red"), box.lty=0, border="white")
}
Run the code above in your browser using DataLab