3

Say I want to create an ordinary xyplot without explicitly specifying axis limits, then how are axis limits calculated?

The following line of code produces a simple scatter plot. However, axis limits do not exactly range from 1 to 10, but are slightly expanded to the left and right and top and bottom sides (roughly by 0.5).

library(lattice)
xyplot(1:10 ~ 1:10, cex = 1.5, pch = 20, col = "black", 
       xlab = "x", ylab = "y")

xyplot_axis_extension

Is there any way to determine the factor by which the axes were expanded on each site, e.g. using trellis.par.get? I already tried the following after executing the above-mentioned xyplot command:

library(grid)
downViewport(trellis.vpname(name = "figure"))
current.panel.limits()
$xlim
[1] 0 1

$ylim
[1] 0 1

Unfortunately, the panel limits are returned as normalized parent coordinates, which makes it impossible to obtain the "real" limits. Any suggestions would be highly appreciated!

Update:
Using base-R plot, the data range (and consequently the axis limits) is by default extended by 4% on each side, see ?par. But this factor doesn't seem to apply to 'trellis' objects. So what I am looking for is an analogue to the 'xaxs' (and 'yaxs') argument implemented in par.

4

1 回答 1

5

轴限制在函数xyplot中计算。extend.limits此函数不是从 lattice 包中导出的,因此要查看它,请键入lattice:::extend.limits. 关于数字向量,此函数从相应数据中传递值范围(c(1, 10)在本例中)。最终限值根据以下等式计算:

lim + prop * d * c(-1, 1)
  • lim是数据的限制,在这种情况下c(1, 10)
  • proplattice.getOption("axis.padding")$numeric,默认情况下是0.07
  • ddiff(as.numeric(lim)),在这种情况下9

这种情况下的结果是c(0.37, 10.63)

如果您有兴趣,从xyplotto的调用堆栈extend.limits

  1. xyplot
  2. xyplot.formula
  3. limits.and.aspect
  4. limitsFromLimitList
  5. extend.limits
于 2015-04-15T10:32:40.030 回答