Equivalent to lwd boxplot option for bwplot

I want the window to be built with thicker lines. In the boxplot function boxplot I just put lwd=2 , but in the bwplot lattice I can pull my hair out and find no solution! enter image description here (with the box, I mean the blue thing in the image above)

Sample code for working 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(...) }) 
+4
source share
3 answers

As John Paul pointed out, line widths are controlled by the box.rectangle and box.umbrella list of graphic lattice parameters. (For your future reference, typing names(trellis.par.get()) is a quick way to scan a list of graphic attributes controlled by this list.)

Here's a slightly cleaner way to set these options for one or more specific shapes:

 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

+6
source

One thing you can do is get the grid settings for the window and change them. 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 them above your bwplot call and it should do it.

The rectangle's rectangle settings also have color, fill, etc.

Edit to add, if you get box.umbrella , you can edit it to change how the lines above and below the field look.

+4
source

There is another feature of the graphs that needs to be mentioned. They are indeed objects, so there are methods to modify their presentation of the list;

 myBW <- bwplot(x ~ type|month, data = df, panel=function(...) { panel.abline(h=0, col="green") panel.bwplot(...) }) newBW <- update(myBW, par.settings=list(box.rectangle=list(lwd=4) )) plot(newBW) # need to print or plot a grid object 

You can also use trellis.focus and apply the optional update function to overlay new data or text.

+3
source

Source: https://habr.com/ru/post/1502658/


All Articles