[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@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.
Re: [R] A couple of issues with lattice::bwplot
On Tue, Feb 25, 2014 at 4:49 PM, Ravi Varadhan ravi.varad...@jhu.edu wrote: 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) as.table = TRUE will change the order and grid.text can be used to plot in npc units (which range from 0 to 1): library(grid) pnl - function(...) { panel.bwplot(...); grid.points(.1, .9, pch = 20, default.units = npc) } bwplot(method ~ Tx.effect|name, data=estimates, box.width=0, coef=0, pch=22, as.table = TRUE, panel = pnl) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@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.
Re: [R] A couple of issues with lattice::bwplot
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 BW ), #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: mac...@northnet.com.au -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ravi Varadhan Sent: Wednesday, 26 February 2014 07:49 To: r-help@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@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. __ R-help@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.