0

In lattice graphics, I am putting x axis ticks and labels on each plot box using scales=list(alternating=3). Is there a parameter that will shift labels left/right (or up/down, for that matter)? For example, my x axis labels are time step numbers. When the last (rightmost) label has more than 3 characters (e.g. "1500"), the rightmost characters extend over the next plot box unless I add a lot of space between boxes (which I'd rather avoid). I'm keeping lots of space between ticks using the 'at' parameter of scales, so there is space to shift "1500" left, e.g. putting the last "0" over the tick mark.

sparrow
  • 1,075
  • 1
  • 10
  • 17
Mars
  • 8,689
  • 2
  • 42
  • 70
  • That's one of the reasons default lattice plot use alternating scales. My trick is to manually specify xlim to 2990 or so. – Dieter Menne Oct 17 '12 at 17:17

2 Answers2

1

Or maybe simply rotate the labels with scale=list(alternating=3, rot = 30) or whatever angle fits. Didier

dd_a
  • 112
  • 2
  • 12
1

Dieter and Didier's solutions are excellent. Thank you. I did further investigation and came up with a third solution. I realized that Lattice is roughly trying to center the tick label above/below the tick mark. Furthermore, if you give it a string as a tick label, it will use the string literally, it seems. So if you add spaces to the end of the string, that will move the text to the left:

# create some data
df <- rbind(data.frame(x=1:1500, y=rnorm(1500), class="left"),
      data.frame(x=1:1500, y=rnorm(1500), class="right"))

xyplot(y ~ x | class, data=df,
       scales=list( at=c(1,seq(500,1500,by=500)),               # I choose ticks explicitly
                    x=list(labels=c(1,500,1000,"1500     "))))  # spaces push "1500" left
Mars
  • 8,689
  • 2
  • 42
  • 70