Good afternoon,

I am working on a plot that requires custom legends to be placed in some
panels of the plot; other panels do not contain legends.  The problem
that I run into is positioning of the legend in individual panels. In
particular, the 'x' and 'y' elements of the key-list are ignored by
draw.key() when it is called from inside a panel function.  As a result,
the legend is placed in the middle of the panel.  The example below
illustrates this problem.

df <- data.frame(x=c(1,1),y=c(1,2),type=c("A","B"))

panel.xyplot.x <- function(...) {
  # draw data
  panel.xyplot(...)

  # create key-list
  pnlid <- panel.number()
  lbl <- ifelse(pnlid==1,"AA","BB")
  pts <- Rows(trellis.par.get("superpose.symbol"),pnlid)
  key <- list(points=pts,text=list(lbl),x=0.1,y=0.9,corner=c(0,1))

  # draw key
  draw.key(key,draw=TRUE)
}

oltc <- xyplot(y~x|type,data=df,panel=panel.xyplot.x)
print(oltc)

I tried using 'vp=current.viewport()' in the call to draw.key() but it
did not help.  Can anybody suggest the proper way to specify position of
the key-list so that it is respected by draw.key() when called within a
panel function?

Sincerely,
Boris Vasiliev.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to