Dear all, I would like to have the same color for the all boxplots from the same panel, but my code below shows the two colors alternating. Thanks! set.seed(42) D1 <- rnorm(200) D2 <- factor(sample(letters[1:2],200,TRUE)) D3 <- factor(sample(letters[3:5],200,TRUE)) DF <- data.frame(x=D1,a=D2,b=D3) print(bwplot(b~x|a,data=DF,col=c("black","black"), par.settings = list(box.rectangle = list(fill=c("darkorange1","limegreen"))), panel=function(x,...,col) { panel.bwplot(x,...,col=col[packet.number()]) } ) ) Thanks, Concha
Hi Concha You nearly got there try: set.seed(42) D1 <- rnorm(200) D2 <- factor(sample(letters[1:2],200,TRUE)) D3 <- factor(sample(letters[3:5],200,TRUE)) DF <- data.frame(x=D1,a=D2,b=D3) print(bwplot(b~x|a,data=DF, par.settings = list(box.dot = list(rep("black",3)), superpose.line = list(col = c("darkorange1","limegreen","magenta")), box.umbrella = list(col = c("darkorange1","limegreen","magenta")), box.rectangle = list(fill=c("darkorange1","limegreen","magenta"), col = c("darkorange1","limegreen","magenta"))), panel=function(x,...,col) { panel.bwplot(x,...,col=col[packet.number()]) } ) ) Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mackay at northnet.com.au At 06:45 8/04/2013, you wrote:>Dear all, > >I would like to have the same color for the all boxplots from the >same panel, but my code below shows the two colors alternating. Thanks! > >set.seed(42) >D1 <- rnorm(200) >D2 <- factor(sample(letters[1:2],200,TRUE)) >D3 <- factor(sample(letters[3:5],200,TRUE)) >DF <- data.frame(x=D1,a=D2,b=D3) >print(bwplot(b~x|a,data=DF,col=c("black","black"), > par.settings = list(box.rectangle = > list(fill=c("darkorange1","limegreen"))), > panel=function(x,...,col) { > panel.bwplot(x,...,col=col[packet.number()]) > } > ) > ) > >Thanks, >Concha > >______________________________________________ >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. >
Richard M. Heiberger
2013-Apr-08 01:38 UTC
[R] Same boxplot colors by panels in lattice (bwplot)
I recommend the panel function from the HH package ## install.packages("HH") ## if necessary library(HH) bwplot(b~x|a,data=DF, panel=panel.bwplot.intermediate.hh, col = c("darkorange1","limegreen","magenta")) Rich On Sun, Apr 7, 2013 at 4:45 PM, Concha Bielza <mcbielza@fi.upm.es> wrote:> Dear all, > > I would like to have the same color for the all boxplots from the same > panel, but my code below shows the two colors alternating. Thanks! > > set.seed(42) > D1 <- rnorm(200) > D2 <- factor(sample(letters[1:2],**200,TRUE)) > D3 <- factor(sample(letters[3:5],**200,TRUE)) > DF <- data.frame(x=D1,a=D2,b=D3) > print(bwplot(b~x|a,data=DF,**col=c("black","black"), > par.settings = list(box.rectangle > list(fill=c("darkorange1","**limegreen"))), > panel=function(x,...,col) { > panel.bwplot(x,...,col=col[**packet.number()]) > } > ) > ) > > Thanks, > Concha > > ______________________________**________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> > PLEASE do read the posting guide http://www.R-project.org/** > posting-guide.html <http://www.R-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Try print(bwplot(b~x|a,data=DF,col=c("black","black"), panel=function(x,...) { pnl = panel.number() if (pnl ==1) panel.bwplot(x,fill="darkorange1",...) else panel.bwplot(x,fill="limegreen",...) } ) ) Someone else may have better ideas Duncan At 18:52 8/04/2013, you wrote:>Dear Duncan, > >I didn't explain it well. >I referred to having the same colors in the boxes to the left and >other different color for all the boxes to the right! >Can you help me? > >Concha >>Hi Concha >> >>You nearly got there try: >> >>set.seed(42) >>D1 <- rnorm(200) >>D2 <- factor(sample(letters[1:2],200,TRUE)) >>D3 <- factor(sample(letters[3:5],200,TRUE)) >>DF <- data.frame(x=D1,a=D2,b=D3) >>print(bwplot(b~x|a,data=DF, >> par.settings = list(box.dot = list(rep("black",3)), >> superpose.line = list(col = >> c("darkorange1","limegreen","magenta")), >> box.umbrella = list(col = >> c("darkorange1","limegreen","magenta")), >> box.rectangle = >> list(fill=c("darkorange1","limegreen","magenta"), >> col = >> c("darkorange1","limegreen","magenta"))), >> panel=function(x,...,col) { >> panel.bwplot(x,...,col=col[packet.number()]) >> } >> ) >> ) >> >>Duncan >> >>Duncan Mackay >>Department of Agronomy and Soil Science >>University of New England >>Armidale NSW 2351 >>Email: home: mackay at northnet.com.au >> >> >> >>At 06:45 8/04/2013, you wrote: >>>Dear all, >>> >>>I would like to have the same color for the all boxplots from the >>>same panel, but my code below shows the two colors alternating. Thanks! >>> >>>set.seed(42) >>>D1 <- rnorm(200) >>>D2 <- factor(sample(letters[1:2],200,TRUE)) >>>D3 <- factor(sample(letters[3:5],200,TRUE)) >>>DF <- data.frame(x=D1,a=D2,b=D3) >>>print(bwplot(b~x|a,data=DF,col=c("black","black"), >>> par.settings = list(box.rectangle = >>> list(fill=c("darkorange1","limegreen"))), >>> panel=function(x,...,col) { >>> panel.bwplot(x,...,col=col[packet.number()]) >>> } >>> ) >>> ) >>> >>>Thanks, >>>Concha >>> >>>______________________________________________ >>>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. >> >>______________________________________________ >>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. > > >-- >Prof. Concha Bielza >Department of Artificial Intelligence >Technical University of Madrid >Campus de Montegancedo, s/n >28660 Boadilla del Monte >Madrid >tel: +34 91 336 7434 >fax: +34 91 352 4819 >http://cig.fi.upm.es/index.php/members/65-concha-bielza > >I try to answer my email quickly, >but I normally check it only once a day.
Richard M. Heiberger
2013-Apr-08 16:07 UTC
[R] Same boxplot colors by panels in lattice (bwplot)
I didn't fully understand the requirement. This version puts the first col in the first panel, the second col in the second panel, and if there more more levels to a, and more colors, then the nth color in the nth panel. bwplot(b ~ x | a, data=DF, panel=function(..., col) { panel.col=col[panel.number()] panel.bwplot.intermediate.hh(..., col=panel.col) }, col = c("darkorange1","limegreen")) On Mon, Apr 8, 2013 at 11:54 AM, Concha Bielza <mcbielza@fi.upm.es> wrote:> > bwplot(b~x|a,data=DF, panel=panel.bwplot.intermediate.hh, > col = c("darkorange1","limegreen","limegreen")) > > It doesn't work. It doesn't put the same color for the boxes within the > same panel... > > > -- > Prof. Concha Bielza > Department of Artificial Intelligence > Technical University of Madrid > Campus de Montegancedo, s/n > 28660 Boadilla del Monte > Madrid > tel: +34 91 336 7434 > fax: +34 91 352 4819 http://cig.fi.upm.es/index.php/members/65-concha-bielza > > I try to answer my email quickly, > but I normally check it only once a day. > >[[alternative HTML version deleted]]