如何让bwplot的中线变粗?

时间:2015-03-30 14:10:53

标签: r lattice

以下代码是使用lattice生成箱图的最小值(对于某些值为minimal ....)的示例。但是那些箱线图上的中线是a)有色和b)非常薄。如何让它们变黑并打勾?

a71<-structure(list(n = structure(c(1L, 2L, 2L, 4L, 4L, 1L, 1L, 4L, 
2L, 1L, 1L, 2L, 2L, 4L, 2L, 2L, 3L, 4L, 1L, 2L, 2L, 3L, 2L, 2L, 
2L, 4L, 3L, 3L, 4L, 2L, 4L, 2L, 1L, 3L, 2L, 3L, 4L, 1L, 4L, 1L, 
3L, 3L, 2L, 1L, 1L, 3L, 3L, 1L, 2L, 4L, 3L, 2L, 3L, 1L, 4L, 1L, 
4L, 2L, 3L, 4L, 4L, 4L, 1L, 3L, 3L, 3L, 4L, 2L, 2L, 2L, 4L, 4L, 
4L, 1L, 4L, 3L, 2L, 2L, 4L, 4L, 3L, 2L, 2L, 2L, 1L, 2L, 3L, 3L, 
3L, 1L, 3L, 3L, 4L, 1L, 3L, 2L, 1L, 3L, 1L, 2L), .Label = c("100", 
"200", "400", "800"), class = "factor"), g = structure(c(3L, 
3L, 1L, 3L, 1L, 3L, 2L, 1L, 1L, 3L, 1L, 2L, 3L, 1L, 2L, 2L, 1L, 
3L, 1L, 2L, 3L, 2L, 2L, 2L, 3L, 1L, 1L, 3L, 3L, 2L, 1L, 1L, 3L, 
1L, 3L, 3L, 1L, 2L, 2L, 2L, 2L, 3L, 2L, 3L, 3L, 1L, 3L, 3L, 1L, 
1L, 1L, 2L, 3L, 1L, 3L, 1L, 3L, 3L, 1L, 2L, 1L, 2L, 2L, 1L, 3L, 
3L, 1L, 3L, 2L, 3L, 1L, 3L, 1L, 1L, 3L, 3L, 2L, 3L, 3L, 3L, 1L, 
3L, 3L, 2L, 3L, 3L, 2L, 2L, 2L, 3L, 2L, 2L, 3L, 1L, 2L, 3L, 3L, 
3L, 1L, 3L), .Label = c("0", "0.5", "1"), class = "factor"), 
    cr = structure(c(1L, 2L, 3L, 1L, 3L, 3L, 2L, 1L, 2L, 3L, 
    3L, 2L, 2L, 3L, 2L, 2L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 1L, 1L, 
    3L, 3L, 3L, 1L, 3L, 1L, 1L, 1L, 2L, 1L, 1L, 3L, 2L, 3L, 1L, 
    3L, 2L, 2L, 2L, 3L, 2L, 3L, 1L, 1L, 2L, 1L, 2L, 2L, 3L, 1L, 
    1L, 1L, 1L, 3L, 3L, 2L, 3L, 1L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 
    1L, 1L, 2L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 3L, 3L, 2L, 1L, 2L, 
    2L, 2L, 2L, 3L, 2L, 2L, 1L, 3L, 2L, 1L, 3L, 1L, 1L, 2L, 2L
    ), .Label = c("-0.4", "0", "0.4"), class = "factor"), bias = c(0.0162558992812201, 
    0.138354243932496, 0.0205686041691062, 0.269714433604472, 
    0.381044037439145, 0.0869422119950729, 0.331379037601084, 
    0.686894150152472, 0.0140922903231885, 0.225078933454863, 
    0.554444988164574, 0.076032683077827, 0.335284040888653, 
    0.0630810396519646, 0.358402154233125, 0.260940142571834, 
    0.141353291599136, 0.0220267076189838, 0.242149484071382, 
    0.278319984858078, 0.193105829691662, 0.0259815643559331, 
    0.318504899459259, 0.00277002060524357, 0.212681621053374, 
    0.418358846098857, 0.358916156777489, 0.438248724241505, 
    0.194398889511096, 0.2266870834128, 0.144338808446284, 0.149227951210927, 
    0.268111328952192, 0.123265441389974, 0.0376832357983068, 
    0.0353605481767078, 0.021227873083535, 0.0385614926552725, 
    0.130640111978654, 0.161865326447675, 0.174151298764213, 
    0.292085797406362, 0.198391364913347, 0.0779507859721407, 
    0.0045571464157577, 0.114734038438965, 0.0469613758623325, 
    0.64238405800387, 0.74508519247034, 0.0251182457091362, 0.217835062247358, 
    0.131159910126724, 0.130034859007596, 0.222418419987533, 
    0.0861715693619894, 0.185660520258661, 0.0940670543815277, 
    0.105680179626893, 0.215966730684923, 0.109008340760604, 
    0.0474735195202623, 0.192326789813641, 0.022147195644035, 
    0.277372858009381, 0.237574293593955, 0.123383946121193, 
    0.46406480500022, 0.123698482002945, 0.671442441453945, 0.0406004813894845, 
    0.260472754754191, 0.0151116521560003, 0.0422855023583402, 
    0.0405517218780402, 0.0441583998205882, 0.0958995639409343, 
    0.37588506579263, 0.098494760958735, 0.0928763466294421, 
    0.111205748449328, 0.413083543393392, 0.0138839674143682, 
    0.22407421093074, 0.72309883706409, 0.423231501875638, 0.141932050342199, 
    0.133808548118004, 0.331500621801688, 0.127652280721512, 
    0.132083126730013, 0.261864564503826, 0.208243130464985, 
    0.18657049493156, 0.333701537602998, 0.404884075502013, 0.470789398932934, 
    0.115008599462104, 0.177984001517338, 0.331717679106776, 
    0.0862418839846533), group = structure(c(3L, 2L, 2L, 3L, 
    1L, 3L, 3L, 2L, 2L, 1L, 3L, 2L, 2L, 2L, 1L, 3L, 2L, 3L, 1L, 
    3L, 1L, 2L, 1L, 3L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 3L, 1L, 1L, 
    3L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 3L, 1L, 2L, 
    3L, 3L, 3L, 1L, 1L, 3L, 2L, 3L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 
    2L, 1L, 1L, 1L, 3L, 2L, 2L, 1L, 1L, 3L, 3L, 3L, 2L, 1L, 3L, 
    3L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 3L, 3L, 1L, 1L, 2L, 3L, 
    1L, 1L, 3L, 2L, 1L, 3L), .Label = c("1", "2", "3"), class = "factor")), .Names = c("n", 
"g", "cr", "bias", "group"), row.names = c(8721L, 6970L, 6686L, 
9624L, 352L, 10545L, 7505L, 4216L, 6170L, 3309L, 10429L, 4302L, 
5602L, 5680L, 1530L, 9234L, 5007L, 8004L, 721L, 10038L, 502L, 
4891L, 2946L, 8502L, 622L, 1972L, 2403L, 3383L, 5880L, 1038L, 
4756L, 9506L, 2169L, 1023L, 8506L, 6239L, 7768L, 3221L, 9536L, 
5981L, 1507L, 4883L, 414L, 3117L, 3993L, 1923L, 9143L, 2673L, 
4430L, 9520L, 9363L, 10602L, 95L, 1141L, 9660L, 4285L, 10704L, 
154L, 531L, 6440L, 4876L, 7052L, 4397L, 3375L, 5075L, 1295L, 
2620L, 334L, 9510L, 4690L, 4288L, 3576L, 2248L, 7693L, 8820L, 
8135L, 4026L, 1906L, 10164L, 8616L, 423L, 5290L, 418L, 6486L, 
4485L, 7042L, 955L, 2215L, 9031L, 8049L, 2323L, 1627L, 4212L, 
8689L, 439L, 2590L, 8649L, 5447L, 1957L, 10570L), class = "data.frame")
 library(lattice)
cl<-c('red','green','blue')
mypanel<-function(...){
        panel.bwplot(...,pch="|",col="black",cex=4,fill=cl)
}
o1<-bwplot(a71$bias~a71$group|a71$cr*a71$g,type=c("l","g"),ylim=c(0,1),panel=mypanel)
plot(o1)

2 个答案:

答案 0 :(得分:1)

通过更改box.rectangle(一个lattice特定图形参数)的某些参数,您可以操纵每个箱形图周围的线(包括中线)。这将改变框周围的所有线条,但不仅仅是中线。

myPars <- list(box.rectangle = list(lwd = 2, col = "black"))

lwd更改线宽(粗细)。 col更改线条的颜色。然后将此列表传递给par.settings中的bwplot参数。

o1 <- bwplot(a71$bias ~ a71$group | a71$cr * a71$g,
    type = c("l", "g"), ylim = c(0, 1), panel = mypanel,
    par.settings = myPars)
plot(o1)

要查看与box.rectangle相关的所有参数,请使用

trellis.par.get("box.rectangle")

答案 1 :(得分:1)

OP很满意@BenBarnes更粗的所有线条,但为了完整性,可以加粗中线。使用box.width默认为1/2:

的事实
bwplot(a71$bias~a71$group|a71$cr*a71$g,type=c("l","g"),ylim=c(0,1),
      panel=function(x,y,...){
        panel.bwplot(x,y,...,pch="|",col="black",cex=4,fill=cl)
        medy <- by(y,list(x),median)
        xx <- sort(unique(as.numeric(x)))
        panel.segments(xx-.25,medy,xx+.25,medy,lwd=2)
      }
)