Anna Zakrisson Braeunlich
2013-Aug-21 08:42 UTC
[R] lattice: bwplot: getting two plots into one.
Dear all, I have problems gettting the following as one graph instead of the two created by this script. I know that with this dummy data, the resulting graph will look like a catastrophy. I have other data I wish to apply this too. Just wanted to supply some dummy data to work with. There may be unnecessary code below. I am still learning. Is it possible to do two different bwplots from different dataframes and then superpose them on to each other? with kind regards A. Zakrisson mydata<- data.frame(factor1 = factor(rep(LETTERS[1:6], each = 80)), #Dummy data factor2 = factor(rep(c(1:2), each = 16)), var1 = rnorm(120, mean = rep(c(0, 3, 5), each = 40), sd = rep(c(1, 2, 3), each = 20))) font.settings <- list( font = 1, cex = 1.3, fontfamily = "serif") my.theme <- list( box.umbrella = list(col = "black"), #Color of deviation lines (95%) box.rectangle = list(col="black"), #Color of the line around the box box.dot = list(col = "black", pch = 3, lty=2, lwd=5, cex=1.3), plot.symbol = list(cex = 1, col = 1, pch= 0), #outlier size and color par.xlab.text = font.settings, mfrow=c(2,2), par.ylab.text = font.settings, axis.line=list(col="black"), #Set "transparent if no axes axis.text = font.settings, strip.shingle=list(col=c("white","white")), superpose.symbol=list(fill=c("white","white")), # boxplots superpose.fill=list(col=c("white","white")), superpose.polygon=list(col=c("white","white")), # legend par.sub=font.settings) bgColors <- c("white", "white", "white") txtColors <- c("black", "black", "black") myStripStyle <- function(which.panel, factor.levels, par.strip.text, custBgCol=par.strip.text$custBgCol, custTxtCol=par.strip.text$custTxtCol,...) { par.settings = list(layout.heights=list(strip=3)) panel.rect(0, 0, 1, 1, col = custBgCol[which.panel], border = 1.2) panel.text(x = 0.5, y = 0.5, font=1, fontfamily = "serif", cex=1.4, lab = factor.levels[which.panel], col = custTxtCol[which.panel]) } bwplot(var1 ~ factor1|factor2, data = mydata, groups=factor2, box.width = 1/3, #width of the boxes panel=panel.superpose, ylab = expression(paste("",delta^{15}, "N")), xlab="Station", par.settings = my.theme, par.strip.text=list(custBgCol=bgColors, custTxtCol=txtColors), strip=myStripStyle, scales = list(alternating = TRUE, x = list(relation = "same", rot=45), y = list(relation = "same")), panel.groups = function(x, y, ..., group.number) { panel.bwplot(x + (group.number-1.8)/3, y, ...) }) trellis.focus("panel", 1, 1) panel.abline(h=0, lty=2) #lwd trellis.unfocus() trellis.focus("panel", 2, 1) panel.abline(h=0, lty=2) #lwd trellis.unfocus() Anna Zakrisson Braeunlich PhD student Department of Ecology, Environment and Plant Sciences Stockholm University Svante Arrheniusv. 21A SE-106 91 Stockholm Sweden/Sverige Lives in Berlin. For paper mail: Katzbachstr. 21 D-10965, Berlin - Kreuzberg Germany/Deutschland E-mail: anna.zakrisson@su.se Tel work: +49-(0)3091541281 Mobile: +49-(0)15777374888 LinkedIn: http://se.linkedin.com/pub/anna-zakrisson-braeunlich/33/5a2/51b><((((º>`•. . • `•. .• `•. . ><((((º>`•. . • `•. .• `•. .><((((º>`•. . • `•. .• `•. .><((((º>[[alternative HTML version deleted]]
Richard M. Heiberger
2013-Aug-21 15:21 UTC
[R] lattice: bwplot: getting two plots into one.
This is the fundamentals bwplot(var1 ~ factor1 | factor2, data=mydata, panel=function(...) { panel.abline(h=0, lty=2, col="gray90") panel.bwplot(...) }) You can add the font control if you need to. The major change I made was to put the panel.abline first. It is part of the background and I don't want it to overwrite the graph. Also, I made it in a light gray so it wouldn't take attention away from the data. Rich On Wed, Aug 21, 2013 at 4:42 AM, Anna Zakrisson Braeunlich < anna.zakrisson@su.se> wrote:> Dear all, > > I have problems gettting the following as one graph instead of the two > created by this script. I know that with this dummy data, the resulting > graph will look like a catastrophy. I have other data I wish to apply this > too. Just wanted to supply some dummy data to work with. > There may be unnecessary code below. I am still learning. > > Is it possible to do two different bwplots from different dataframes and > then superpose them on to each other? > with kind regards > > A. Zakrisson > > mydata<- data.frame(factor1 = factor(rep(LETTERS[1:6], each = 80)), #Dummy > data > factor2 = factor(rep(c(1:2), each = 16)), > var1 = rnorm(120, mean = rep(c(0, 3, 5), each = 40), > sd = rep(c(1, 2, 3), each = 20))) > > font.settings <- list( font = 1, cex = 1.3, fontfamily = "serif") > > my.theme <- list( > box.umbrella = list(col = "black"), #Color of deviation lines (95%) > box.rectangle = list(col="black"), #Color of the line around the box > box.dot = list(col = "black", pch = 3, lty=2, lwd=5, cex=1.3), > plot.symbol = list(cex = 1, col = 1, pch= 0), #outlier size and color > par.xlab.text = font.settings, > mfrow=c(2,2), > par.ylab.text = font.settings, > axis.line=list(col="black"), #Set "transparent if no axes > axis.text = font.settings, > strip.shingle=list(col=c("white","white")), > superpose.symbol=list(fill=c("white","white")), # boxplots > superpose.fill=list(col=c("white","white")), > superpose.polygon=list(col=c("white","white")), # legend > par.sub=font.settings) > > bgColors <- c("white", "white", "white") > txtColors <- c("black", "black", "black") > myStripStyle <- function(which.panel, factor.levels, par.strip.text, > custBgCol=par.strip.text$custBgCol, > custTxtCol=par.strip.text$custTxtCol,...) { > par.settings = list(layout.heights=list(strip=3)) > panel.rect(0, 0, 1, 1, > col = custBgCol[which.panel], > border = 1.2) > panel.text(x = 0.5, y = 0.5, > font=1, > fontfamily = "serif", > cex=1.4, > lab = factor.levels[which.panel], > col = custTxtCol[which.panel]) > } > > bwplot(var1 ~ factor1|factor2, data = mydata, > groups=factor2, > box.width = 1/3, #width of the boxes > panel=panel.superpose, > ylab = expression(paste("",delta^{15}, "N")), > xlab="Station", > par.settings = my.theme, > par.strip.text=list(custBgCol=bgColors, > custTxtCol=txtColors), > strip=myStripStyle, > scales = list(alternating = TRUE, > x = list(relation = "same", rot=45), > y = list(relation = "same")), > panel.groups = function(x, y, ..., group.number) { > panel.bwplot(x + (group.number-1.8)/3, y, ...) > }) > trellis.focus("panel", 1, 1) > panel.abline(h=0, lty=2) #lwd > trellis.unfocus() > trellis.focus("panel", 2, 1) > panel.abline(h=0, lty=2) #lwd > trellis.unfocus() > > > Anna Zakrisson Braeunlich > PhD student > > Department of Ecology, Environment and Plant Sciences > Stockholm University > Svante Arrheniusv. 21A > SE-106 91 Stockholm > Sweden/Sverige > > Lives in Berlin. > For paper mail: > Katzbachstr. 21 > D-10965, Berlin - Kreuzberg > Germany/Deutschland > > E-mail: anna.zakrisson@su.se > Tel work: +49-(0)3091541281 > Mobile: +49-(0)15777374888 > LinkedIn: http://se.linkedin.com/pub/anna-zakrisson-braeunlich/33/5a2/51b > > ><((((º>`•. . • `•. .• `•. . ><((((º>`•. . • `•. .• `•. .><((((º>`•. . • > `•. .• `•. .><((((º> > > [[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. > >[[alternative HTML version deleted]]