Dear friends, I have two questions regarding the use of lattice. First some code: ## begin code z <- cbind(rep(c("BIC", "ICL", "s_v", "Q_v", "sig-q", "s_lsk", "s_lML", "s_mlsk", "s_mlML", "s_la8", "s_haar"), each = 250), rep(c(5, 10, 20, 30, 50), each = 50)) z <- rbind(cbind(z, 0), cbind(z, 20), cbind(z, 40)) z <- cbind(z, rnorm(n = nrow(z))) z <- as.data.frame(z) names(z) <- c("Method", "sigma", "INU", "Error") sigma <- as.numeric(levels(z$sigma)) sigmaExprList <- lapply(sigma, function(s) bquote(italic(sigma) == . (s))) sigmaExpr <- as.expression(sigmaExprList) bwplot(Error~Method | sigma, data = z[z[,"INU"] == 0,],scales=list (rot=90), horiz = F, xlab = "Method", ylab = "Relative Error", strip = function(which.given, which.panel, var.name, strip.levels = FALSE, strip.names = TRUE, ...) { strip.default(which.given, which.panel, var.name = sigmaExpr[which.panel], strip.levels = FALSE, strip.names = TRUE, ...) }, layout = c(5,1), col = "red") ## end code Question 1: how do I "force" the display of the "Method" in the plotting to be in the same order (i.e., in the order of "BIC", "ICL", "s_v", "Q_v", "sig-q", "s_lsk", "s_lML", "s_mlsk", "s_mlML", "s_la8", "s_haar") as the input. As you may notice, it puts them in its own merry order (I suspect in ascii alphabetical order, but that conjecture is based entirely on my very few sample attempts). Question 2: I want to have 3x5 plots of the respective boxplots. Something like: Error ~ Method | sigma + INU? But I want the labels for the sigma and the INU to be only in the column and the rows (vertically here) as appropriate, in order to save plotting space. How do I go about doing this? Please reply through the mailing list so that others may also benefit. In any case, many thanks again for reading and for any help and pointers! Best wishes, Ranjan -- Important Notice: This mailbox is ignored: e-mails are set to be deleted on receipt. For those needing to send personal or professional e-mail, please use appropriate addresses. ____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
Answer to you first question, try this at the start of bwplot to specify ordering: bwplot(Error~factor(Method, levels = unique(Method)) On Sat, Jul 21, 2012 at 2:42 PM, Ranjan Maitra <maitra.mbox.ignored at inbox.com> wrote:> Dear friends, > > I have two questions regarding the use of lattice. First some code: > > > ## begin code > > z <- cbind(rep(c("BIC", "ICL", "s_v", "Q_v", "sig-q", > "s_lsk", "s_lML", "s_mlsk", "s_mlML", "s_la8", > "s_haar"), each = 250), rep(c(5, 10, 20, 30, 50), each = 50)) > z <- rbind(cbind(z, 0), cbind(z, 20), cbind(z, 40)) > z <- cbind(z, rnorm(n = nrow(z))) > z <- as.data.frame(z) > names(z) <- c("Method", "sigma", "INU", "Error") > sigma <- as.numeric(levels(z$sigma)) > sigmaExprList <- lapply(sigma, function(s) bquote(italic(sigma) == . > (s))) sigmaExpr <- as.expression(sigmaExprList) > bwplot(Error~Method | sigma, data = z[z[,"INU"] == 0,],scales=list > (rot=90), horiz = F, xlab = "Method", ylab = "Relative Error", > strip = function(which.given, which.panel, var.name, > strip.levels = FALSE, > strip.names = TRUE, ...) { > strip.default(which.given, which.panel, > var.name = sigmaExpr[which.panel], > strip.levels = FALSE, > strip.names = TRUE, ...) > }, > layout = c(5,1), col = "red") > > > ## end code > > Question 1: how do I "force" the display of the "Method" in the > plotting to be in the same order (i.e., in the order of "BIC", "ICL", > "s_v", "Q_v", "sig-q", "s_lsk", "s_lML", "s_mlsk", "s_mlML", "s_la8", > "s_haar") as the input. As you may notice, it puts them in its own > merry order (I suspect in ascii alphabetical order, but that conjecture > is based entirely on my very few sample attempts). > > Question 2: I want to have 3x5 plots of the respective boxplots. > Something like: > Error ~ Method | sigma + INU? > But I want the labels for the sigma and the INU to be only in the > column and the rows (vertically here) as appropriate, in order to save > plotting space. How do I go about doing this? > > Please reply through the mailing list so that others may also benefit. > In any case, many thanks again for reading and for any help and > pointers! > > Best wishes, > Ranjan > > > -- > Important Notice: This mailbox is ignored: e-mails are set to be > deleted on receipt. For those needing to send personal or professional > e-mail, please use appropriate addresses. > > ____________________________________________________________ > FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop! > > ______________________________________________ > 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.-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.
Bert Gunter
2012-Jul-23 05:05 UTC
[R] two questions re: the use of lattice (Q1 SOLVED, not Q2)
There's a typo below. It's Deepayan Sarkar. -- Bert On Sun, Jul 22, 2012 at 9:55 PM, Bert Gunter <bgunter at gene.com> wrote:> inline. > > -- Bert > > On Sun, Jul 22, 2012 at 8:26 PM, Ranjan Maitra > <maitra.mbox.ignored at inbox.com> wrote: >> >>> Just reset the levels of z$sigma (and also redefine sigmaExpr): >>> >>> z$sigma <- factor(z$sigma, >>> levels = c(5,10,20,30,50)) # new levels order >>> >>> sigmaExprList <- lapply(as.numeric(levels(z$sigma)), >>> function(s) bquote(sigma == .(s))) >>> sigmaExpr <- as.expression(sigmaExprList) >>> INUExpr <- paste0("INU = ", c(0,20,40), "%") >>> >>> p <- bwplot(Error ~ Method | sigma + INU, data = z, >>> scales = list(rot=90), horiz = FALSE, >>> layout = c(5,3), col = "red") >>> >>> useOuterStrips(p, >>> strip = strip.custom( >>> factor.levels = sigmaExpr), >>> strip.left = strip.custom( >>> factor.levels = INUExpr) >>> ) >>> >> >> One last question: how do I draw a line h = 0, lty =2 through each plot? > > ?panel.abline > > If you don't know how to use this in a panel function, time to start > doing your own "homework." Panel functions are central to the trellis > paradigm, so an honest effort to learn these details will be worth the > effort. A good place to start is the examples in the above help file. > There are also numerous online tutorials and websites. Google. Also > check Seepyan Sarkar's (lattice's author) web page. > > -- Bert >> >> Thanks a lot, this has been quite a learning experience for me wrt >> lattice! >> >> Ranjan >> >> ____________________________________________________________ >> GET FREE 5GB EMAIL - Check out spam free email with many cool features! >> Visit http://www.inbox.com/email to find out more! >> >> ______________________________________________ >> 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. > > > > -- > > Bert Gunter > Genentech Nonclinical Biostatistics > > Internal Contact Info: > Phone: 467-7374 > Website: > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm