bwr图的格标签
我想在格子图中标记每个盒子和胡须上的一些统计数据。 下面是一个通用示例bwr图的格标签,r,lattice,labels,bwplot,R,Lattice,Labels,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
#---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。必须有一种方法来访问每个面板中每个框和胡须的长度、平均值、中值等信息?我认为您必须自己计算值,例如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
}
)
非常感谢你对这个问题的迅速解决。然而,我发现在一个真实的数据示例中,它并不能很好地工作,在这个示例中,我在每个面板中的每个框和每个胡须都有不同数量的数据,并且在没有数据的情况下也有级别。然而,这个解决方案无疑为我指明了正确的方向,因为我了解到,数字标签必须与每个面板中的方框和胡须图的数量相匹配。通过使用ifpacket.number==1{ltext等等,如果为每个面板设置一组标签,我可以将标签设置为正确的位置和正确的顺序。