5

我想用较粗的线条绘制方框。在boxplot函数中我只是简单地放了lwd=2,但在格子中bwplot我可以把头发拉出来,但还没有找到解决方案!在此处输入图像描述 (我的意思是上图中的蓝色框)

可使用的示例代码:

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

3 回答 3

7

正如 John Paul 所指出的,线宽由lattice 图形参数列表的box.rectangle和组件控制。box.umbrella(供您将来参考,键入names(trellis.par.get())是一种快速扫描由该列表控制的图形属性列表的方法。)

这是为一个或多个特定图形设置这些选项的一种更简洁的方法:

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(...)
       })

在此处输入图像描述

于 2013-09-17T17:38:41.043 回答
4

您可以做的一件事是获取盒子的格子设置,然后更改它们。尝试

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)

将这些放在您的 bwplot 调用之上,它应该这样做。

矩形框设置也有颜色、填充等。

编辑添加如果你box.umbrella可以编辑它以更改框上方和下方的线条的外观。

于 2013-09-17T17:22:40.333 回答
3

格子图还有一个需要提及的特征。它们实际上是对象,因此存在修改它们的列表表示的方法;

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

您还可以使用trellis.focus和应用进一步的更新功能来覆盖新的数据或文本。

于 2013-09-17T17:47:05.070 回答