Hi, I would like to add a key to my trellis plot using draw.key. Here is what I want: 3 x 6 key where the first row is a header. row 1: empty, "S-R Mapping", "R^2" row 2: pch=17, "Color", 0.951 row 2: pch=17, "Shape", 0.934 ect... The problem is that I would like the cell in the upper left corner to be empty (a placeholder) with the remaining entries in that column the appropriate pch symbols. Is there a way to do that using draw.key? My other option is to create a grid table from scratch. But, I'd like to capitalize on draw.key if I can. Suggestions? If draw.key won't work, suggestions on how to do it with grid? Thanks, Steve [[alternative HTML version deleted]]
On 4/5/06, Steven Lacey <slacey at umich.edu> wrote:> Hi, > > I would like to add a key to my trellis plot using draw.key. Here is what I > want: > > 3 x 6 key where the first row is a header. > > row 1: empty, "S-R Mapping", "R^2" > row 2: pch=17, "Color", 0.951 > row 2: pch=17, "Shape", 0.934 > ect... > > The problem is that I would like the cell in the upper left corner to be > empty (a placeholder) with the remaining entries in that column the > appropriate pch symbols. Is there a way to do that using draw.key? My other > option is to create a grid table from scratch. But, I'd like to capitalize > on draw.key if I can. Suggestions? If draw.key won't work, suggestions on > how to do it with grid?Does col = c('transparent', ...) not work? Deepayan
Try this... xyplot(y~x,data=data.frame(x=1:10,y=1:10)) keyArgs <- list() keyArgs <- list(points=list(pch=c(NA,rep(17,5)),lwd=2,col=c(NA,c("red", "chartreuse3", "black", "cyan", "blue"))), text=list(lab=c("S-R Mapping", "Color","Shape","Letter","Compatible","Incompatible"),cex=c(1.2,1,1,1,1,1)), text=list(lab=c(expression(R^2),as.character(rep(0.999,5))),cex=c(1.2,1,1,1, 1,1))) keyArgs$between <- c(1,0,5) keyArgs$columns <- 1 keyArgs$column.between <- 1 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() Steve -----Original Message----- From: Deepayan Sarkar [mailto:deepayan.sarkar at gmail.com] Sent: Wednesday, April 05, 2006 11:53 PM To: Steven Lacey Cc: r-help at stat.math.ethz.ch Subject: Re: [R] skipping rows in trellis key On 4/5/06, Steven Lacey <slacey at umich.edu> wrote:> Yes, that works! Thanks! > > On a related note... When I draw my key there is not sufficient > padding between the last line of the key and the border line. For > instance, the vertical line in "p" often drops below the border. Is > there an easy way to add padding between the last row of the key and > the border?Example please. Deepayan
Hi, Steve, I think you can trick it by adding an empty level with a small cex: keyArgs <- list(points=list(pch=c(NA,rep(17,5),NA),lwd=2, col=c(NA,c("red", "chartreuse3", "black", "cyan", "blue")),NA), text=list(lab=c("S-R Mapping","Color","Shape","Letter","Compatible","Incompatible",""),cex=c(1.2,1,1,1,1,1,.2)), text=list(lab=c(expression(R^2),as.character(rep(0.999,5)),""),cex=c(1.2,1,1,1,1,1,.2))) HTH, --sundar Steven Lacey wrote:> Try this... > > xyplot(y~x,data=data.frame(x=1:10,y=1:10)) > keyArgs <- list() > keyArgs <- list(points=list(pch=c(NA,rep(17,5)),lwd=2,col=c(NA,c("red", > "chartreuse3", "black", "cyan", "blue"))), > text=list(lab=c("S-R Mapping", > "Color","Shape","Letter","Compatible","Incompatible"),cex=c(1.2,1,1,1,1,1)), > > text=list(lab=c(expression(R^2),as.character(rep(0.999,5))),cex=c(1.2,1,1,1, > 1,1))) > keyArgs$between <- c(1,0,5) > keyArgs$columns <- 1 > keyArgs$column.between <- 1 > 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() > > Steve > > -----Original Message----- > From: Deepayan Sarkar [mailto:deepayan.sarkar at gmail.com] > Sent: Wednesday, April 05, 2006 11:53 PM > To: Steven Lacey > Cc: r-help at stat.math.ethz.ch > Subject: Re: [R] skipping rows in trellis key > > > On 4/5/06, Steven Lacey <slacey at umich.edu> wrote: > >>Yes, that works! Thanks! >> >>On a related note... When I draw my key there is not sufficient >>padding between the last line of the key and the border line. For >>instance, the vertical line in "p" often drops below the border. Is >>there an easy way to add padding between the last row of the key and >>the border? > > > Example please. > > Deepayan > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html