i looking legend in top of following plot describes polygons , blue point in frames.
require(lattice) grid<-data.frame(f=rnorm(1000),t=rep(c("a","b"),each=500)) histogram(~f|t, data=grid, params=c(1,2) ,layout=c(2,1), xlab = "",ylab="",as.table=true #,par.settings = list(superpose.polygons = list(col=c(4))) #,key = list(polygons = list(col=c(4)),space="top",columns=1 # ,text = list("text") # ) #, auto.key = list(polygons = true,title = "survived", columns = 1) ,type="density",breaks=40 ,panel=function(x,params,...){ panel.grid() panel.histogram(x,...,col=8) lab<-format(params[panel.number()], digits=2, nsmall=2) panel.points(params[panel.number()],0,pch=16,col=4) panel.text(1, 0.05, labels = lab) })
note, late answer.
the trick have 2 text labels (one bars , other points), have 1 rectangle (the bars) , 1 point in legend. can make work adding 2 text= arguments key= argument. lattice add elements key in same order list them in code.
require(lattice) grid<-data.frame(f=rnorm(1000),t=rep(c("a","b"),each=500)) histogram(~f|t, data=grid, params=c(1,2) ,layout=c(2,1), xlab = "",ylab="",as.table=true ,key=list(space="top", #puts key on top of panels rectangles=list(col=8), #draws gray box text=list("gray bars"), #label box points=list(col=4,pch=16), #draw blue point text=list("blue dots") #label point ) ,type="density",breaks=40 ,panel=function(x,params,...){ panel.grid() panel.histogram(x,...,col=8) lab<-format(params[panel.number()], digits=2, nsmall=2) panel.points(params[panel.number()],0,pch=16,col=4) panel.text(1, 0.05, labels = lab) })
Comments
Post a Comment