Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of boxplot lwd parameter for bwplot

I want to have the box plotted with thicker lines. In boxplot function I simply put lwd=2, but in the lattice bwplot I can pull my hair out and haven't found a solution!enter image description here (with the box I mean the blue thing in the image above)

Sample code to work with:

require(lattice)
set.seed(123)
n <- 300
type <- sample(c("city", "river", "village"), n, replace = TRUE)
month <- sample(c("may", "june"), n, replace = TRUE)
x <- rnorm(n)
df <- data.frame(x, type, month)

bwplot(x ~ type|month, data = df, panel=function(...) {
    panel.abline(h=0, col="green")
    panel.bwplot(...)
})
like image 534
Tomas Avatar asked Sep 17 '13 16:09

Tomas


2 Answers

As John Paul pointed out, the line widths are controlled by the the box.rectangle and box.umbrella components of lattice's graphical parameter list. (For your future reference, typing names(trellis.par.get()) is a fast way to scan the list of graphical attributes controlled by that list.)

Here's a slightly cleaner way to set those options for one or more particular figures:

thickBoxSettings <- list(box.rectangle=list(lwd=2), box.umbrella=list(lwd=2))

bwplot(x ~ type|month, data = df, 
       par.settings = thickBoxSettings,
       panel = function(...) {
           panel.abline(h=0, col="green")
           panel.bwplot(...)
       })

enter image description here

like image 198
Josh O'Brien Avatar answered Sep 23 '22 20:09

Josh O'Brien


One thing you can do is get the trellis settings for the box, and change those. Try

rect.settings<-trellis.par.get("box.rectangle") #gets all rectangle settings
rect.settings$lwd<-4  #sets width to 4, you can choose what you like
trellis.par.set("box.rectangle",rect.settings)

Put these above your bwplot call and it should do it.

The box rectangle settings also has color, fill etc.

Edit to add if you get box.umbrella you can edit it to change what the lines above and below the box look like.

like image 31
John Paul Avatar answered Sep 23 '22 20:09

John Paul