[R] A couple of issues with lattice::bwplot
Duncan Mackay
dulcalma at bigpond.com
Wed Feb 26 00:47:46 CET 2014
Hi Ravi
str(estimates)
'data.frame': 240 obs. of 4 variables:
$ Tx.effect: num -0.2321 -0.1097 0.0409 0.0546 0.1069 ...
$ method : chr "Bayes-DS" "Bayes-DS" "Bayes-DS" "Bayes-DS" ...
$ name : chr "X0=0, scenario1" "X0=1, scenario1" "X1=0, scenario1"
"X1=1, scenario1" ...
$ type : chr "Point" "LCL" "UCL" "Point" ...
is a character variable so control the order make it a factor with the
levels in the order that you want
If you have the argument as.table = TRUE this will get you part/all the way
there
I find it easier to put the trellis settings in as par.settings (as I
frequently have different requirements for the one graphic device when
multiple plotting) eg
bwplot(method ~ Tx.effect|name, data=estimates,
par.settings = list(box.rectangle = list(lty=1, lwd=2),
box.umbrella = list(lty=1, lwd=2),
strip.background = list(col = "transparent") #
added: easier to see if publishing/printing in B&W
),
#strip = strip.custom(factor.levels = unique(estimates$name), #or
whatever
# par.strip.text = list(cex = 0.85) ),
as.table = TRUE,
box.width=0,
coef=0,
pch=22)
and for the strip names you can have a variable and then put what you want
there
Regards
Duncan
Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Ravi Varadhan
Sent: Wednesday, 26 February 2014 07:49
To: r-help at r-project.org
Subject: [R] A couple of issues with lattice::bwplot
Hi All,
I am using lattice::bwplot to plot the results of a subgroup analysis for
different simulation scenarios. I have 4 subgroups, 5 methods of estimating
treatment effect in subgroups, and 4 scenarios. I am plotting the subgroup
effect and its upper and lower CI.
I have 2 issues that I am unable to resolve:
1. How can I control the order in which the panels are plotted? For
example, I would like to bottom and top rows to be switched, and for 2nd and
3rd rows to be switched.
2. How can I plot a point within each panel at a fixed coordinate?
My code is as follows:
library(lattice)
trellis.par.set("box.rectangle", list(lty=1, lwd=2))
trellis.par.set("box.umbrella", list(lty=1, lwd=2))
n.param <- 16
est.method <- c("Bayes-DS", "EB", "MLE-DS", "Naive", "Stand")
est.type <- c("Point", "LCL", "UCL")
est.names <- c("Int.", paste0("X", 2:n.param))
est.names <- c(outer(c("X0=0", "X0=1","X1=0", "X1=1"), paste0(", scenario",
1:4), function(x,y) paste0(x, y)))
n.methods <- length(est.method)
n.types <- length(est.type)
estimates <- data.frame(Tx.effect=sort(rnorm(n.param*n.methods*n.types,
mean=0.5, sd=0.2)),
method=rep(est.method, each=n.param*n.types),
name=rep(est.names, times=n.types*n.methods),
type=rep(est.type, times=n.param*n.methods))
truth <- runif(16) # I would like to plot these points, one per each panel
bwplot(method ~ Tx.effect|name, data=estimates, box.width=0, coef=0, pch=22)
I would greatly appreciate any help.
Thank you,
Ravi
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list