1

When attempting to adjust the font size in directlabels, using list(cex=2), the function undesirably adds labels to every single point.

library(lattice)
library(directlabels)
foo <- data.frame(x=1:10, y=c(1:5, (1:5)^2), z=c(1:10))
direct.label( xyplot( y + z ~ x, foo, type=c('l','g') ),
              list(cex=2) )

I'd prefer the default label placement (with one label per group) that comes with the ordinary call:

direct.label( xyplot( y + z ~ x, foo, type=c('l','g') ) )

Specifying a position method like first.points below, gives the desired one label per group, but this is not the same default label placement method I am after.

direct.label( xyplot( y + z ~ x, foo, type=c('l','g') ),
              list("first.points", cex=2) )

Does anyone know which which position method reproduces the default automatic placement method? Or is there another way to change label font size without specifying the position method?

Sandy Muspratt
  • 31,719
  • 12
  • 116
  • 122
Bryan
  • 933
  • 1
  • 7
  • 21

1 Answers1

2

The method used in this case is "lines2":

direct.label(xyplot( y + z ~ x, foo, type=c('l','g') ),
             list("lines2", list(cex=2)) )

enter image description here

FYI, I figured that out by taking a quick look at getAnywhere("direct.label.trellis"), which pointed me towards panel.superpose.dl(). To learn what method it selected in the line reading

if (is.null(method)) 
    method <- default.picker("trellis")

I did debug(panel.superpose.dl), ran the code in your second code block, and stepped through with the debugger until I could check which method got picked by default.picker().

Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
  • Many thanks for showing your thought process. This suggests that there is no simple way to maintain automation of method selection while adjusting font size, but it does narrow the answer down to a few default functions including `lines2`, `maxvar.qp`, and `maxvar.points`, which show up inside the `get("defaultpf.trellis")` call from `default.picker("trellis")`. Whew! – Bryan Apr 05 '15 at 00:55
  • Yeah, it really shouldn't be that hard to have both automatic/heuristic selection of placement method **and** slightly tweaked graphical parameters. Might be worth a note to the package author, especially if you dig a little deeper and can suggest a simple fix. – Josh O'Brien Apr 06 '15 at 01:32