Anna Zakrisson Braeunlich
2013-Aug-13 14:00 UTC
[R] Lattice: bwplot - changing box colors in legend and plot when using panel.groups = function... and panel = panel.superpose
Hi, Yes, I have searched stack overflow. My issue is to simply change coloring in boxes and legend in my bwplot. I have done this many times in lattice, but now I have been tweaking the plot somewhat and I can no longer apply the color changes. I would really appreciate some help. A. Zakrisson Here is some dummy data and my script: mydata<- data.frame(factor1 = factor(rep(LETTERS[1:6], each = 80)), 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, fontfamily = "serif") my.theme <- list( box.umbrella = list(col = "black"), box.rectangle = list(fill= rep(c("black", "black"),2)), box.dot = list(col = "black", pch = 3, cex=2), plot.symbol = list(cex = 1, col = 1, pch= 0), #outlier size and color par.xlab.text = font.settings, par.ylab.text = font.settings, axis.text = font.settings, par.sub=font.settings) bwplot(var1 ~ factor1, data = mydata, groups = factor2, box.width = 1/3, #width of the boxes auto.key = list(points = FALSE, rectangles = TRUE, space = "right", title="Year", cex.title=1), panel = panel.superpose, ylab = "var1", xlab="factor1", par.settings = my.theme, panel.groups = function(x, y, ..., group.number) { panel.bwplot(x + (group.number-1.8)/3, y, ...) }) 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-13 16:18 UTC
[R] Lattice: bwplot - changing box colors in legend and plot when using panel.groups = function... and panel = panel.superpose
I don't see a question in what you wrote. Your graph has some similarities to some of my examples. Please look at the demo in the HH package ## install.packages("HH") ## if necessary library(HH) demo("bwplot.examples", package="HH") Rich On Tue, Aug 13, 2013 at 10:00 AM, Anna Zakrisson Braeunlich < anna.zakrisson@su.se> wrote:> Hi, > > Yes, I have searched stack overflow. > > My issue is to simply change coloring in boxes and legend in my bwplot. I > have done this many times in lattice, but now I have been tweaking the plot > somewhat and I can no longer apply the color changes. > I would really appreciate some help. > A. Zakrisson > > Here is some dummy data and my script: > > mydata<- data.frame(factor1 = factor(rep(LETTERS[1:6], each = 80)), > 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, fontfamily = "serif") > my.theme <- list( > box.umbrella = list(col = "black"), > box.rectangle = list(fill= rep(c("black", "black"),2)), > box.dot = list(col = "black", pch = 3, cex=2), > plot.symbol = list(cex = 1, col = 1, pch= 0), #outlier size and color > par.xlab.text = font.settings, > par.ylab.text = font.settings, > axis.text = font.settings, > par.sub=font.settings) > > bwplot(var1 ~ factor1, data = mydata, groups = factor2, > box.width = 1/3, #width of the boxes > auto.key = list(points = FALSE, > rectangles = TRUE, space = "right", > title="Year", cex.title=1), > panel = panel.superpose, > ylab = "var1", > xlab="factor1", > par.settings = my.theme, > panel.groups = function(x, y, ..., group.number) { > panel.bwplot(x + (group.number-1.8)/3, y, ...) > }) > > > 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]]
Kevin Wright
2013-Aug-13 16:28 UTC
[R] Lattice: bwplot - changing box colors in legend and plot when using panel.groups = function... and panel = panel.superpose
I think I understand your question. You need to make sure that you are setting the right parameters in your theme. Use trellis.par.get() to have a look at the MANY possible settings. For example, in your case, to have the boxplots and rectangles be the same color: my.theme <- list( box.umbrella = list(col = "black"), box.rectangle = list(fill= rep(c("black", "black"),2)), box.dot = list(col = "black", pch = 3, cex=2), plot.symbol = list(cex = 1, col = 1, pch= 0), #outlier size and color par.xlab.text = font.settings, par.ylab.text = font.settings, axis.text = font.settings, #strip.shingle=list(col=c("red","blue")), superpose.symbol=list(fill=c("red","blue")), # boxplots #superpose.fill=list(col=c("red","blue")), superpose.polygon=list(col=c("red","blue")), # legend par.sub=font.settings) Kevin Wright On Tue, Aug 13, 2013 at 9:00 AM, Anna Zakrisson Braeunlich < anna.zakrisson@su.se> wrote:> Hi, > > Yes, I have searched stack overflow. > > My issue is to simply change coloring in boxes and legend in my bwplot. I > have done this many times in lattice, but now I have been tweaking the plot > somewhat and I can no longer apply the color changes. > I would really appreciate some help. > A. Zakrisson > > Here is some dummy data and my script: > > mydata<- data.frame(factor1 = factor(rep(LETTERS[1:6], each = 80)), > 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, fontfamily = "serif") > my.theme <- list( > box.umbrella = list(col = "black"), > box.rectangle = list(fill= rep(c("black", "black"),2)), > box.dot = list(col = "black", pch = 3, cex=2), > plot.symbol = list(cex = 1, col = 1, pch= 0), #outlier size and color > par.xlab.text = font.settings, > par.ylab.text = font.settings, > axis.text = font.settings, > par.sub=font.settings) > > bwplot(var1 ~ factor1, data = mydata, groups = factor2, > box.width = 1/3, #width of the boxes > auto.key = list(points = FALSE, > rectangles = TRUE, space = "right", > title="Year", cex.title=1), > panel = panel.superpose, > ylab = "var1", > xlab="factor1", > par.settings = my.theme, > panel.groups = function(x, y, ..., group.number) { > panel.bwplot(x + (group.number-1.8)/3, y, ...) > }) > > > 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. > >-- Kevin Wright [[alternative HTML version deleted]]