0

我想在格子 bwplot 中标记每个框和晶须的一些统计数据。下面是一个通用示例。

#---Some dummy data
Rock<-c("Rock1","Rock2","Rock3")
Zone<-as.data.frame(c("Zone10","Zone11","Zone12"))
Domain<-as.data.frame(c("Domain1","Domain2"))
Dt <- as.data.frame(rnorm(100))
Dt<-merge(Dt,Zone)
Dt<-merge(Dt,Rock)
Dt<-merge(Dt,Domain)
names(Dt)<-c("Data","Zone","Rock","Domain")

#--- Use aggregate to get the number of values for each combination of three factors (100 each)
aggregate(Data~Rock*Zone*Domain,Dt,FUN=length)

require(lattice)
#--- create a lattice plot and attempt to label the number of value associated with each BnW
bwplot(Rock~Data|Zone*Domain,
    data=Dt,
    xlim=c(-5,5),
       panel=function(...){
        panel.bwplot(...)
        panel.text(-4,c(1,2,3),length(x))
    }

)

这不起作用 - 不知道为什么我得到的标签是 45 而不是 100。必须有一种方法可以访问每个面板中每个框和胡须的长度、平均值、中值等内容?

4

1 回答 1

0

我认为您必须自己计算值,例如 plyr 包很容易(尽管您也可以继续使用聚合)。

library(plyr)
agg=ddply(Dt,c("Zone","Rock","Domain"),summarise,length=length(Data), max=max(Data),median=median(Data))  # max or median or ... to have the xvalues were you want to plot the values of length

require(lattice)
bwplot(Rock~Data|Zone*Domain,
   data=Dt,
   xlim=c(-5,5),
   panel=function(...){
     panel.bwplot(...)
     panel.text(agg$max+1,c(1,2,3),agg$length)  # plus one to not mask the last dot
   }
   )
于 2014-10-06T13:04:22.190 回答