Hi,
I want to do the following:
1) create a trellis plot with 1 x 1 layout
2) add a key in the upper right hand corner of the plotting region (i.e.,
the panel), but after the initial call to trellis
3) resize the resulting device graphics device without changing the relative
position of the key
For instance, the code below draws the key relative to the device
window--not the plotting area.
xyplot(y~x,data=data.frame(x=1:10,y=1:10),par.setting=list(background="white
"),col="black")
keyArgs <- list()
keyArgs <- list(points=list(pch=17,lwd=2,col=c("transparent","red",
"chartreuse3", "black", "cyan", "blue","transparent")),
text=list(lab=c("S-R Mapping",
"Color","Shape","Letter","Compatible","Incompatible",""),cex=c(1.2,1,1,1,1,1
,0.2)),
text=list(lab=c(expression(R^2),as.character(rep(0.999,5)),""),cex=c(1.2,1,1
,1,1,1,0.2)))
keyArgs$between <- c(1,0,5)
keyArgs$background <- "white"
keyArgs$border <- TRUE
drawKeyArgs <- list(key=keyArgs,draw=FALSE)
keyArgs$draw <- FALSE
key <- do.call("draw.key",drawKeyArgs)
vp1<-viewport(x=1,y=1,height=unit(1,"grobheight",key),width=unit(1,"grobwidt
h",key),just=c("right","top"))
pushViewport(vp1)
grid.draw(key)
popViewport()
If I embed the call to draw.key into the panel function, where presumably
the plotting area is the current viewport, then it works.
panel.test <- function(x,y,...){
panel.xyplot(x,y,...)
keyArgs <- list()
keyArgs <- list(points=list(pch=17,lwd=2,col=c("transparent","red",
"chartreuse3", "black", "cyan", "blue","transparent")),
text=list(lab=c("S-R Mapping",
"Color","Shape","Letter","Compatible","Incompatible",""),cex=c(1.2,1,1,1,1,1
,0.2)),
text=list(lab=c(expression(R^2),as.character(rep(0.999,5)),""),cex=c(1.2,1,1
,1,1,1,0.2)))
keyArgs$between <- c(1,0,5)
keyArgs$background <- "white"
keyArgs$border <- TRUE
drawKeyArgs <- list(key=keyArgs,draw=FALSE)
keyArgs$draw <- FALSE
key <- do.call("draw.key",drawKeyArgs)
vp1<-viewport(x=1,y=1,height=unit(1,"grobheight",key),width=unit(1,"grobwidt
h",key),just=c("right","top"))
pushViewport(vp1)
grid.draw(key)
popViewport()
}
xyplot(y~x,data=data.frame(x=1:10,y=1:10),par.setting=list(background="white
"),col="black",panel=panel.test)
But, I don't want to write panel functions that are specific to the key. I'd
like to draw the plot, access the plotting area viewport, push it, and add
the key.
Something may be possible with baseViewports, but I can't get that to work
properly with a 1 x 1 lattice plot, and the relative position of the key
changes when the device is rescaled. Is there an easy way to do this in the
initial call to xyplot? My read of the documentation is that a key may be
positioned in the npc coordinates of the device region, but not the plotting
region. Is that correct?
Thanks,
Steve
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html