Search code examples
rlattice

Export the scale_x and scale_y values displayed in the xyplot of the lattice package


Is there some way to export the scale_x and scale_y values displayed in the xyplot of the lattice package? I run for example the following code but no name seems to contain these values.

library(lattice)
library(latticeExtra)

myplot <- xyplot(cars$speed~cars$dist)
print(myplot) 
# xx': 0, 20, ..., 120
# yy': 5, 10, ..., 25

str(myplot)

Thank in advance all of you.


Solution

  • For that plotting scenario, you can extract the x ticks with

    myplot$xscale.components(lim = myplot$x.limits)$bottom$ticks$at
    

    and y ticks with

    myplot$yscale.components(lim = myplot$y.limits)$left$ticks$at
    

    You can find more complete versions of these calls in the lattice:::plot.trellis function